Rails 3.2.17; Error: Can't mass-assign protected attributes: key
awesome opened this issue · 1 comments
awesome commented
SOLUTION:
# in config/initializers/settler.rb
class Setting < ActiveRecord::Base
attr_accessible *column_names
end
Settler.load!
SOURCES:
- http://stackoverflow.com/a/15932630
- http://stackoverflow.com/questions/8961994/how-to-make-all-model-attributes-accessible-for-mass-assignment
Line 15 in fb005d9
BACKGROUND:
irb(main):011:0> Setting.count
(0.3ms) SELECT COUNT(*) FROM "settings" WHERE (deleted = 'f' or deleted IS NULL)
=> 0
irb(main):012:0> Settler.load!
Setting Load (0.1ms) SELECT "settings".* FROM "settings" WHERE "settings"."key" = 'ask_mailer' LIMIT 1
ActiveModel::MassAssignmentSecurity::Error: Can't mass-assign protected attributes: key
from /Users/dev/.gem/ruby/2.1.8/gems/activemodel-3.2.17/lib/active_model/mass_assignment_security/sanitizer.rb:48:in `process_removed_attributes'
from /Users/dev/.gem/ruby/2.1.8/gems/activemodel-3.2.17/lib/active_model/mass_assignment_security/sanitizer.rb:20:in `debug_protected_attribute_removal'
from /Users/dev/.gem/ruby/2.1.8/gems/activemodel-3.2.17/lib/active_model/mass_assignment_security/sanitizer.rb:12:in `sanitize'
from /Users/dev/.gem/ruby/2.1.8/gems/activemodel-3.2.17/lib/active_model/mass_assignment_security.rb:230:in `sanitize_for_mass_assignment'
from /Users/dev/.gem/ruby/2.1.8/gems/activerecord-3.2.17/lib/active_record/attribute_assignment.rb:75:in `assign_attributes'
from /Users/dev/.gem/ruby/2.1.8/gems/activerecord-3.2.17/lib/active_record/base.rb:498:in `initialize'
from /Users/dev/.gem/ruby/2.1.8/gems/activerecord-3.2.17/lib/active_record/persistence.rb:44:in `new'
from /Users/dev/.gem/ruby/2.1.8/gems/activerecord-3.2.17/lib/active_record/persistence.rb:44:in `create'
from /Users/dev/.gem/ruby/2.1.8/gems/settler-2.0.1/lib/settler.rb:23:in `block (2 levels) in load!'
from /Users/dev/.gem/ruby/2.1.8/gems/settler-2.0.1/lib/settler.rb:22:in `each'
from /Users/dev/.gem/ruby/2.1.8/gems/settler-2.0.1/lib/settler.rb:22:in `block in load!'
from /Users/dev/.gem/ruby/2.1.8/gems/activerecord-3.2.17/lib/active_record/scoping/default.rb:41:in `block in unscoped'
from /Users/dev/.gem/ruby/2.1.8/gems/activerecord-3.2.17/lib/active_record/relation.rb:241:in `block in scoping'
from /Users/dev/.gem/ruby/2.1.8/gems/activerecord-3.2.17/lib/active_record/scoping.rb:98:in `with_scope'
from /Users/dev/.gem/ruby/2.1.8/gems/activerecord-3.2.17/lib/active_record/relation.rb:241:in `scoping'
from /Users/dev/.gem/ruby/2.1.8/gems/activerecord-3.2.17/lib/active_record/scoping/default.rb:41:in `unscoped'
from /Users/dev/.gem/ruby/2.1.8/gems/settler-2.0.1/lib/settler.rb:21:in `load!'
from (irb):12
from /Users/dev/.gem/ruby/2.1.8/gems/railties-3.2.17/lib/rails/commands/console.rb:47:in `start'
from /Users/dev/.gem/ruby/2.1.8/gems/railties-3.2.17/lib/rails/commands/console.rb:8:in `start'
from /Users/dev/.gem/ruby/2.1.8/gems/railties-3.2.17/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'irb(main):013:0>