Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 Rails希望保存attr_访问器属性_Ruby On Rails 3 - Fatal编程技术网

Ruby on rails 3 Rails希望保存attr_访问器属性

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

在我的模型中有一些自定义属性访问器

当我尝试使用params[:model]创建新模型时,出现以下错误:

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