22
23

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rails4からRails5にアップデートしたらDeviceでエラーが出た

Last updated at Posted at 2016-07-11

Rails4で開発を始めたアプリケーションをRails5にアップデートしたら
```undefined method `for' for #Devise::ParameterSanitizer:0x***



原因のファイルは app/controllers/application_controller.rb で、

```rb:app/app/controllers/application_controller.rb
  def configure_permitted_parameters
    devise_parameter_sanitizer.for(:sign_up) { |user_params| user_params.permit(:username, :password, :password_confirmation) }
    devise_parameter_sanitizer.for(:sign_in) { |user_params| user_params.permit(:username, :password, :remember_me) }
  end 

と書いていたからだった。
Deviseの公式にあるように、forメソッドをpermitメソッドで書き換えてやるとうまくいった。

app/app/controllers/application_controller.rb
def configure_permitted_parameters
  devise_parameter_sanitizer.permit(:sign_up) do |user_params|
    user_params.permit(:username, :password, :password_confirmation)
  end
  devise_parameter_sanitizer.permit(:sign_in) do |user_params|
    user_params.permit(:username, :password, :remember_me)
  end
end 

####参考にしたサイト
http://stackoverflow.com/questions/37341967/rails-5-undefined-method-for-for-devise-on-line-devise-parameter-sanitizer

22
23
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
22
23

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?