5
votes

I'm using Rails 4 and I'm trying to add first name and last name fields to the sign up process. I'm using Devise to handle authentication.

I've added first_name and last_name columns to my user model through a migration. I also added the following to my application_controller.rb file:

before_filter :configure_permitted_parameters, if: :devise_controller?

protected

def configure_permitted_parameters
  devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:first_name, :last_name, :email, :password, :password_confirmation, :remember_me) }
  devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:email, :password, :remember_me) }
  devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:first_name, :last_name, :email, :password, :password_confirmation, :current_password) }
end

However when I sign up, the first_name and last_name field can be left blank and even when they are populated the values are not saved to the user object.

How can I:

  1. Force those fields to be required on sign up? I tried adding 'validates_presence_of :first_name, :last_name, :email' to the user model but had to remove it since the form for some reason always thinks the first_name and last_name fields are blank.
  2. Update devise create action so that it saves the values passed in through the devise/registrations/new.html.erb file?
  3. I have a Person model that i want to associate with this user (associations are created successfully and i have forms that edit both person and user fields but not sure how to build that into the devise sign up process.

Any help would be appreciated.

1
This article should help: jacopretorius.net/2014/03/… It shows how to customise RegistrationsControllerJonas
Thanks Jonas. ^ This is the correct answer to the question.inmydelorean

1 Answers