对mass_assignment_authorizer 的更改导致 Ruby on Rails 3.1 中出现错误
railscast 中的防止批量分配在 Rails 3.1 中不再有效。
给出的错误是:
参数数量错误(1 代表 0)
)
app/models/user.rb:20:in `mass_assignment_authorizer'
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'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您尝试在 Ryan's Railcasts 中实现覆盖技术,但使用 Rails 3.1.0,那么将模型中的私有 def 重写为:
我发现这清除了
上面的错误(即只需添加 (role = :default),并且也与上面的答案相关
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:
I found this cleared the
error above (ie just adding (role = :default), and also correlates with the answer above
查看源代码,至少在 master 中,mass_assignment_authorizer 有一个默认选项 :default ,如图所示 此处。
您使用的是哪个版本的 Rails 3.1?,可能值得通过更改 Gemfile 来尝试它:
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: