2012-04-13 1 views
0

Ich habe eine Rails 3.2.3, ich habe ein Formular mit zwei verschachtelten Modellen, wenn ich versuche, das Formular abzuschicken, erhalte ich diese Fehlermeldung:Schienen 3.2.3: Gewusst wie: zugeordnete Modelle zuordnen?

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 
:

ActiveModel::MassAssignmentSecurity::Error in ExperimentsController#create 

Can't mass-assign protected attributes: descriptions_attributes, circuits_attributes 

Hier meine Modelle ist

Ich kann attr_accessible für ein Feld hinzufügen, aber was ist mit den verschachtelten Modellen?

Antwort

3

Versuche Zugabe:

class Experiment < ActiveRecord::Base 
    attr_accessible :title, :intro_text, :descriptions_attributes, :circuits_attributes 
    [...] 

In Ihrem Experiment Modell.

+0

danke, es hat funktioniert – simo