开发者

Changes to mass_assignment_authorizer cause errors in Ruby on Rails 3.1

开发者 https://www.devze.com 2023-03-22 08:27 出处:网络
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)

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)

开发者_如何学Pythonfor

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'
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号