0
我有一個導軌3.2.3,我有兩個嵌套模型形式,當我嘗試提交表單,我得到這個錯誤:Rails 3.2.3:如何批量分配相關模型?
ActiveModel::MassAssignmentSecurity::Error in ExperimentsController#create
Can't mass-assign protected attributes: descriptions_attributes, circuits_attributes
這裏是我的模型:
class Experiment < ActiveRecord::Base
attr_accessible :title, :intro_text
has_many :circuits, :dependent => :destroy
has_many :descriptions, :dependent => :destroy
accepts_nested_attributes_for :descriptions, :reject_if => lambda { |a| a[:data].blank? }, :allow_destroy => true
accepts_nested_attributes_for :circuits, :reject_if => lambda { |a| a[:data].blank? }, :allow_destroy => true
end
class Circuit < ActiveRecord::Base
attr_accessible :data, :title
belongs_to :experiment
end
class Description < ActiveRecord::Base
attr_accessible :data, :title
belongs_to :experiment
end
我可以爲一個字段添加attr_accessible
,但是,嵌套模型呢?
謝謝,它的工作 – simo 2012-04-14 13:00:41