デバイスを使用する登録ページに 1 つのフィールドを追加しようとしています。Deviseドキュメントの指示に従いました。新しいフィールドは「役割」フィールドです。私はすでにそれをデータベースに正常に移行しました。私は今、サインアップが機能するようにしようとしています。新しいアプリケーション コントローラは次のとおりです。
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
def devise_parameter_sanitizer
if resource_class == User
User::ParameterSanitizer.new(User, :user, params)
else
super # Use the default one
end
end
end
そして、変更された User モデルは次のとおりです。
class User::ParameterSanitizer < Devise::ParameterSanitizer
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
def sign_up
default_params.permit(:email, :role)
end
end
これら 2 つのファイルを追加すると、サーバーはロードできなくなります。役割フィールドを正常に追加するにはどうすればよいですか?
編集
ここに私のroutes.rbファイルがあります
devise_for :users
root 'static_pages#home'
get 'student' => 'static_pages#index'