0
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

当我尝试使用 depot 和 famille 字段创建新文章时出现此错误,我该如何解决?

ActiveModel::MassAssignmentSecurity::Error in ArticlesController#create
Can't mass-assign protected attributes: depot, famille
4

1 回答 1

1

添加到您的文章类:

attr_accessible :code, :designation, :depot_id, :famille_id
于 2013-04-06T22:02:20.177 回答