35
36

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.

【Rails】Deviseでのstrong parameters指定はdevise_parameter_sanitizer.forではなくdevise_parameter_sanitizer.permitを使うようになったらしい

Last updated at Posted at 2016-09-25

Railsの認証を簡単にするプラグインdeviseで、strong parametersをいじろうとした。

適当に日本語サイトなどを調べてdevise_parameter_sanitizer.forをApplicationControllerに追加したが、上手くいかない。ということでGithubのREADMEを読んでみると、どうやら変更があったようだ

こんな感じで書くといいらしい。

class ApplicationController < ActionController::Base
  before_action :configure_permitted_parameters, if: :devise_controller?

  protected

  def configure_permitted_parameters
    devise_parameter_sanitizer.permit(:sign_up, keys: [:username])
  end
end

ちなみにpermitの第一引数は、:sign_in, :sign_up, :account_updateのいずれか。

35
36
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
35
36

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?