我知道这个问题已经被问了很多,但通常提出的解决方案是将config.active_record.whitelist_attributes
设置为false。我已经试过了,仍然得到这个 问题:Rails质量分配问题
Can't mass-assign protected attributes: ingredient_attributes
我有两个型号:recipe.rb和ingredient.rb。他们有一对多的关系,每个配方可以有很多成分。
recipe.rb
class Recipe < ActiveRecord::Base
attr_accessible :description, :name, :yield, :recipe_id
has_many :ingredient, :dependent => :destroy
accepts_nested_attributes_for :ingredient
end
ingredient.rb
class Ingredient < ActiveRecord::Base
belongs_to :recipe
attr_accessible :ingredient, :listorder, :recipe_id
end
出于好奇,你为什么宣布':recipe_id''attr_accessible'在'Recipe'模式? – zeantsoi
我想我已经读过这是一个解决大规模分配问题的方法,但它没有起作用,所以我可以把它拿出来。 –
您收到的错误消息表示一对一关系,而不是一对多关系。但是,您的模型看起来正确。也许有些东西在处理你的表单时很腥......你可以发布你的控制器和视图吗? – zeantsoi