从Ruby 1.9.3上的Rails 3.2.13升级到Rails 4.0.0。
设计3.0.0.rc不会批量分配。我遵循了我发现的所有建议,从这里描述的两种方法开始:https://github.com/plataformatec/devise#strong-parameters。
登录/注销有效,但注册不是:
Started POST "/users" for 127.0.0.1 at 2013-07-03 21:01:47 -0500
Processing by RegistrationsController#create as HTML
Parameters: {"utf8"=>"✓",
"authenticity_token"=>"5QPwkbXULEsF5nCiMMK7zd04baZ5kOecgqV2BdRnSEc=",
"user"=>{"first_name"=>"test", "last_name"=>"testor", "email"=>"asdhd@gmail.com",
"username"=>"testy", "password"=>"[FILTERED]",
"password_confirmation"=>"[FILTERED]"}, "commit"=>"Register"}
WARNING: Can't mass-assign protected attributes for User: email, password,
password_confirmation, first_name, last_name, username
这是Devise的问题吗?有人有解决方案吗?
谢谢!
答案 0 :(得分:2)
问题是我在railscast http://railscasts.com/episodes/415-upgrading-to-rails-4之后使用的gem'en protected_attributes':
...
# add these gems to help with the transition:
gem 'protected_attributes'
...
我没有想到gem会阻碍Rails 4方法,比如params.require(:incoming_model).permit(....)。我可能误会了。
取出宝石可以解决问题。这里提到的第一种方法(懒惰方式)有效:https://github.com/plataformatec/devise#strong-parameters。
答案 1 :(得分:0)
在 application.rb 中将 config.active_record.whitelist_attributes 设为false。
将 include ActiveModel :: ForbiddenAttributesProtection 添加到模型中
看看:http://blog.remarkablelabs.com/2012/12/strong-parameters-rails-4-countdown-to-2013