问题描述
在rails 3.2.1中,我有一个模型:
In rails 3.2.1, I have a model:
class Player < ActiveRecord::Base
attr_accessor :password
attr_accessible :email, :password
attr_accessible :email, :password, :confirmed, :as => :admin
end
我不断收到以下内容的ActiveModel::MassAssignmentSecurity::Error
:
I keep getting a ActiveModel::MassAssignmentSecurity::Error
for the following:
params[:player]
#=> {:email => "some@email.com", :password => "12345", :confirmed => true)
player = Player.new(params[:player])
为什么我要做的就是忽略:confirmed
属性并继续进行业务时,为什么会发生这种情况? 文档使我似乎应该能够做到这一点,但是我一直在得到异常,这确实对我很重要,因为我做错了或者文档做错了.
Why is this happening when all I want it to do is ignore the :confirmed
attribute and move on with it's business. The documentation makes it seem like I should be able to do that, but I keep getting this exception and it's really getting to me because either I am doing it wrong or the docs are wrong.
我很乐意为此提供帮助.
I'd love any help with this.
推荐答案
在development.rb
中注释此行:
config.active_record.mass_assignment_sanitizer = :strict
严格设置会引发错误,默认设置只会记录警告.
The strict setting will raise an error and the default setting will just log a warning.
这篇关于Rails atttr_accesible无法按记录工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!