I am trying to add one field to my registration page that uses devise. I followed the instructions in the Devise document. The new field is the "role" field. I have already succesfully migrated it to the database. I am now trying to make it so that the signup works. Here is the new applicationcontroller:
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
And here is the changed User model:
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
Once I added these two files, the server cannot even load. How do I successfully add the role field?
EDIT
Here is my routes.rb file
devise_for :users
root 'static_pages#home'
get 'student' => 'static_pages#index'
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…