从表单创建新对象时出现以下错误:Can't mass-assign protected attributes: feature_ids
。在我的模型中,我有以下内容:
class Outboard < ActiveRecord::Base
attr_accessible :make, :model, :price, :features
has_many :features, :through => :Outboardfeature
has_many :Outboardfeature
end
class Feature < ActiveRecord::Base
attr_accessible :name
has_many :outboards, :through => :Outboardfeature
has_many :Outboardfeature
end
class Outboardfeature < ActiveRecord::Base
attr_accessible :feature_id, :outboard_id
belongs_to :feature, :class_name => "Feature", :foreign_key => "feature_id"
belongs_to :outboard, :class_name => "Outboard", :foreign_key => "outboard_id"
end
我无法看到从错误中可以访问feature_ids的位置,就像我的外置模型中我可以访问的功能一样。
答案 0 :(得分:1)
将:feature_ids
添加到外接模特attr_accessible
。