LoginSignup
0
0

More than 3 years have passed since last update.

deviseに追加したカラムを保存する方法

Posted at

概要

deviseはデフォルトでemailやpasswordのカラムは入っている。しかし、nameやnicknameなど新しくカラムを追加した際、以下の手順で保存を行えるようにする

app/controllers/application_controller.rb

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

    private
    def configure_permitted_parameters
      devise_parameter_sanitizer.permit(:sign_up, keys: [:name, :nickname])
    end
  end
end

上記のkeysの中に追加したカラム名を入れることによって保存が行えるようになる。

0
0
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
0
0