Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

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

More than 3 years have passed since last update.

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

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

https://github.com/plataformatec/devise#strong-parameters

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

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のいずれか。

ry023
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away