向我的rails web app添加用户名时出错(设计gem)

时间:2016-12-31 09:24:25

标签: ruby-on-rails devise

在我的rails网络应用中添加用户名时,我遇到了一些错误。

我在链接中说了https://rubyonrailshelp.wordpress.com/2014/01/07/adding-a-username-to-the-user-admin-model/

浏览器似乎有错误:

NoMethodError in Devise::RegistrationsController#edit 

undefined method `for' for #<Devise::ParameterSanitizer:0xa8342f0>

 def configure_permitted_parameters
    devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:username, :email, :password, :password_confirmation, :remember_me) }
    devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:username, :email, :password, :remember_me) }
    devise_parameter_sanitizer.for(:account_update) {|u| u.permit(:username, :email, :password, :password_confirmation, :current_password)} #for account update

application_controller.rb

中出现错误的原因

1 个答案:

答案 0 :(得分:0)

尝试

devise_parameter_sanitizer.permit(:sign_up, keys: [:name])

正如@J.D.所述,请使用before_action而不是before_filter