RailsのDeviseでユーザー名を登録できるようにしたいと考えております。
すでにusersテーブルにはnameカラムを追加しており、ビュー(new.html.erb)にもユーザー名の入力フォームは表示されています。
あとはdeviseの調整ができれば動くのかな、というところです。
まず、http://localhost:3000/users/sign_upで登録をすると、以下のエラーが発生します。
NoMethodError in Devise::RegistrationsController#create undefined method `username' for #<User:0x007fce0720c588> else match = match_attribute_method?(method.to_s) match ? attribute_missing(match, *args, &block) : super end end
application_controller.rbは以下のように記述しています。
class ApplicationController < ActionController::Base before_action :configure_permitted_parameters, if: :devise_controller? protect_from_forgery with: :exception #strong parametersを設定し、nameを許可 def configure_permitted_parameters devise_parameter_sanitizer.permit(:sign_up, keys: [:name]) end end
user.rbは以下のとおりです。
class User < ActiveRecord::Base # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable has_many :reviews #usernameを必須・一意とする validates_uniqueness_of :username validates_presence_of :username end
ユーザー名のカラムをnameとしているため、それで齟齬が生じているのでしょうか。
提示すべきファイルに不足がございましたらご指摘いただけますと幸いです。
恐れ入りますが、ご回答よろしくお願い致します。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。