Ruby on rails 3 Rails希望保存attr_访问器属性
在我的模型中有一些自定义属性访问器 当我尝试使用params[:model]创建新模型时,出现以下错误:Ruby on rails 3 Rails希望保存attr_访问器属性,ruby-on-rails-3,Ruby On Rails 3,在我的模型中有一些自定义属性访问器 当我尝试使用params[:model]创建新模型时,出现以下错误: ActiveModel::MassAssignmentSecurity::Error (Can't mass-assign protected attributes: entity_select, office_select): class Expedient < ActiveRecord::Base belongs_to :enterprise has_many :doc
ActiveModel::MassAssignmentSecurity::Error (Can't mass-assign protected attributes: entity_select, office_select):
class Expedient < ActiveRecord::Base
belongs_to :enterprise
has_many :document
attr_accessor :entity_select
attr_accessor :office_select
...
使
实体\u选择
和办公室\u选择
属性可访问:
class Expedient < ActiveRecord::Base
# Add:
attr_accessible :entity_select, :office_select
类权宜之计
这不是说它需要可访问性吗?我不认为它试图被持久化。你是对的,我已经更新/编辑了这个问题。谢谢我的评论没有回答问题吗?!让他们可以接近。对不起,我没有在这里跟踪你。。。怎样?你的意思是把它们包括在attr_accessible中吗?现在我可以接受答案了。我认为在进行大规模分配时,attr_访问器不需要attr_访问的地方可以访问attr_。Thanks@mongeta没问题。我认为mass赋值只是检查setter方法,看看它们是否可以访问,尽管我不记得有什么确切的信息。
@expedient=Expedient.new.attributes=params[:expedient]
class Expedient < ActiveRecord::Base
# Add:
attr_accessible :entity_select, :office_select