3

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'
dangerousdave
  • 6,331
  • 8
  • 45
  • 62

2 Answers2

9

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

Mitch
  • 1,017
  • 1
  • 13
  • 25
0

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'
Andrew Nesbitt
  • 5,976
  • 1
  • 32
  • 36