1
提交表單後我收到ActiveRecord::UnknownAttributeError
。錯誤是unknown attribute: conversation_id
就行@question = @conversation.questions.new(params[:question])
提交表單時ActiveRecord :: UnknownAttributeError
我加了conversation_id
屬性,但它沒有做出改變。不知道該錯誤可能指向了什麼。
問題控制器:
def create
@conversation = Conversation.create
@question = @conversation.questions.new(params[:question])
if @question.save
@message = current_user.messages.new(:subject => "You have a question from #{@question.sender_id}",
:body => @question.question)
@question.message = @message
@question.save
redirect_to :back, notice: 'Your question was saved successfully. Thanks!'
else
render :new, alert: 'Sorry. There was a problem saving your question.'
end
end
end
對話模型:
class Conversation < ActiveRecord::Base
acts_as_messageable
attr_accessible :answer, :question, :sender_id, :recipient_id, :conversation_id
has_many :questions
end
用戶模式:
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
問題型號:
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
你忘了在'questions'表中添加'conversation_id'字段嗎? –
什麼是進入函數的參數哈希值? – MCBama
@KirtiThorat啊那會是正確的!簡單地看看!謝謝 – pwz2000