Changes to mass_assignment_authorizer cause errors in Ruby on Rails 3.1
Protecting against mass assignment as in this railscast no longer works in Rails 3.1.
Error given is:
wrong number of arguments (1 for 0)
app/models/user.rb:20:in `mass_assignment_authorizer'
If you're trying to implement the override technique in Ryan's Railcasts, but using Rails 3.1.0, then re-writing the private def in the model to:
def mass_assignment_authorizer(role = :default)
super + (accessible || [])
end
I found this cleared the
wrong number of arguments (1 for 0)
error above (ie just adding (role = :default), and also correlates with the answer above
Looking in the source it appears that, at least in master, there is a default option of :default for mass_assignment_authorizer as seen here.
Which version of rails 3.1 are you using?, it may be worth trying it against head by changing your Gemfile:
gem 'rails', :git => 'git@github.com:rails/rails.git'
精彩评论