LoginSignup
2
3

More than 3 years have passed since last update.

[Rails] deviseで追加した:usernameがデータベースに追加されない

Posted at

問題

  • sign_up画面でユーザーネームを入力しても保存されない
  • rollback transactionとでてなぜかDBに保存できない

前提

  • deviseを導入していて、新規カラムを追加している
    (今回は:usernameカラム)
  • エラーメッセージを日本語化している

やったこと

解決方法

application_controllerに

application_controller
class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception
  before_action :configure_permitted_parameters, if: :devise_controller?

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

と記入:ok_hand:

2
3
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
2
3