ruby on rails - ActiveRecord::UnknownAttributeError when submitting form -


i getting activerecord::unknownattributeerror after submitting form. error unknown attribute: conversation_id on line @question = @conversation.questions.new(params[:question])

i added conversation_id attributes did not make change. not sure else error pointing to.

questions controller:

  def create     @conversation = conversation.create     @question = @conversation.questions.new(params[:question])       if @question.save         @message = current_user.messages.new(:subject => "you have question #{@question.sender_id}",                                :body => @question.question)         @question.message = @message         @question.save         redirect_to :back, notice: 'your question saved successfully. thanks!'       else         render :new, alert: 'sorry. there problem saving question.'       end     end   end 

conversation model:

class conversation < activerecord::base   acts_as_messageable    attr_accessible :answer, :question, :sender_id, :recipient_id, :conversation_id    has_many :questions  end 

user model:

  attr_accessible :role, :notification_id, :sender_id, :receiver_id, :conversation_id, :no_email, :average_response_time, :response_rate, :response_total, :name, :time_zone, :code, :lat, :lon, :city, :age, :age_end, :password_confirmation, :about_me, :feet, :inches, :password, :birthday, :career, :children, :education, :email, :ethnicity, :gender, :height, :name, :password_digest, :politics, :religion, :sexuality, :user_drink, :user_smoke, :username, :zip_code 

question model:

class question < activerecord::base   attr_accessible :answer, :question, :sender_id, :recipient_id, :conversation_id   belongs_to :user    belongs_to :sender,:class_name => 'user',:foreign_key => 'sender_id'    belongs_to :recipient,:class_name => 'user',:foreign_key => 'recipient_id'    belongs_to :message    belongs_to :conversation     end 

you receiving activerecord::unknownattributeerror - unknown attribute: conversation_id on following line

@question = @conversation.questions.new(params[:question]) 

because didn't create conversation_id field in questions table required have setup 1-m association between conversation , question model.

to resolve error need add conversation_id field in questions table.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -