我不知道为什么,但下面的代码就停止工作了(我什至没有注意到它是怎么发生的)
routes.rb
devise_for :users, components: {registrations: 'registrations', sessions: 'sessions'}
registations_controller.rb
class RegistrationsController < Devise::RegistrationsController
before_filter :configure_permitted_parameters
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up).push(:name, :surname, :username, :email, :avatar)
devise_parameter_sanitizer.for(:account_update).push(:name, :surname, :email, :avatar)
end
end
正如我所说,之前一切正常,但现在我得到:
Processing by Devise::RegistrationsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"lvuPOmTRqv6XUQ/O1g4Q9VNvzD7DgGCHocY/OlAvKHEIvWAHvlS982hxSZZzzAESCpmL5QTUcTLw/c9ME/sUFQ==", "user"=>{"name"=>"John", "surname"=>"Doe", "username"=>"foobar", "email"=>"foobar@example.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Register"}
Unpermitted parameters: name, surname, email
配置:
- rails 4.2.5
- 设计 3.5.6
P.S.:现在我终于明白为什么我应该用单元测试覆盖我的代码并使用 Travis CI
最佳答案
自 4.1 以来,for
方法已被弃用。改用这个:
class ApplicationController < ActionController::Base
before_action :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
attributes = [:name, :surname,:username, :email, :avatar]
devise_parameter_sanitizer.permit(:sign_up, keys: attributes)
devise_parameter_sanitizer.permit(:account_update, keys: attributes)
end
end
关于ruby-on-rails - 设计:不允许的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35668465/