使用嵌套属性时的批量分配警告

我对rails上的编程和ruby都很陌生。 我已经关注了http://ruby.railstutorial.org/然后我开始观看http://railscasts.com的剧集。 我想要做的是“以单一forms处理多个模型”。 下面你将看到我的模型和他们的assosications以及我试图从用户获取信息的表单视图。

我的建模是那样的;

有雇主,雇主有面试和面试有问题。

Customquestion模型:

class Customquestion < ActiveRecord::Base attr_accessible :content belongs_to :interview validates :content, length: {maximum: 300} validates :interview_id, presence: true end 

面试模型:

 class Interview < ActiveRecord::Base attr_accessible :title, :welcome_message belongs_to :employer has_many :customquestions, dependent: :destroy accepts_nested_attributes_for :customquestions validates :title, presence: true, length: { maximum: 150 } validates :welcome_message, presence: true, length: { maximum: 600 } validates :employer_id, presence: true default_scope order: 'interviews.created_at DESC' end 

形成新的面试;

  

Create New Interview


3 %>

当我填写表格所需的信息并提交时,我得到以下错误;

 Can't mass-assign protected attributes: customquestions_attributes Application Trace | Framework Trace | Full Trace app/controllers/interviews_controller.rb:5:in `create' Request Parameters: {"utf8"=>"✓", "authenticity_token"=>"cJuBNzehDbb5A1Zb14BjBfz1eOsjBCDzGhYKT7q6A0k=", "interview"=>{"title"=>"", "welcome_message"=>"", "customquestions_attributes"=>{"0"=>{"content"=>""}}}, "commit"=>"Create Interview"} 

我希望我已经为你们提供了足够的信息来了解这个案例的问题。

先感谢您

只需按照错误消息中的内容进行操作:尝试将attr_accessible :customquestions_attributes添加到Interview模型中:

 class Interview < ActiveRecord::Base attr_accessible :title, :welcome_message, :customquestions_attributes ...