adding a user profile on sign up with Devise

By | 01/08/2017

I have user registration form however to keep it simple I don’t want the user to have to enter lots of details during the initial registration, however want to have them complete a profile page.

I wanted the profile to be created on registration so set up a has_one relationship in my model:

class User < ApplicationRecord
    has_one :profile, dependent: :destroy

For the profile to be created on registration I needed edit the crate method in the registrations controller.

class Users::RegistrationsController < Devise::RegistrationsController
def create
  super
  if resource.save
    resource.create_profile
  end
end
A profile will automatically get created when ever a user registers - now to get them to fill it in!