I\'m trying to add a name attribute to the User model provided by Devise. I added a \"name\" column to my database, and changed the sign up view so that it asks for the use
Use like this
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:username, :email, :password, :password_confirmation, :remember_me) }
devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:login, :username, :email, :password, :remember_me) }
devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:username, :email, :password, :password_confirmation, :current_password) }
end
Add additional fields at the end.
uncomment some of the generated code:
class Users::RegistrationsController < Devise::RegistrationsController
before_filter :configure_sign_up_params, only: [:create]
protected
def configure_sign_up_params
devise_parameter_sanitizer.for(:sign_up) << :name
end
end
private
def sign_up_params
params.require(:user).permit(:name,:email,:gender,:age,:password,:password_confirmation) if params[:user].present?
end
Add this in the controller that extends devise's default registration controller
Yes. Add :name
to attr_accessible
in User Model
in your user model locate;
attr_accessible :email, :password, :password_confirmation, :remember_me
and add :name on the end
Write this code inside the ApplicationController class...
before_action :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) << :name