Search code examples
ruby-on-railsruby-on-rails-3mass-assignment

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)

for

app/models/user.rb:20:in `mass_assignment_authorizer'

Solution

  • 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