问题描述:

class Depot < ActiveRecord::Base

attr_accessible :code, :designation

has_many :articles

end

class Famille < ActiveRecord::Base

attr_accessible :code, :designation

has_many :articles

end

class Article < ActiveRecord::Base

belongs_to :depot

belongs_to :famille

attr_accessible :code, :designation

end

This error appears when I try to create a new article with depot and famille fields, how can I resolve it?

ActiveModel::MassAssignmentSecurity::Error in ArticlesController#create

Can't mass-assign protected attributes: depot, famille

网友答案:

Add to your Article class:

attr_accessible :code, :designation, :depot_id, :famille_id
相关阅读:
Top