How to add fields to the Devise registration form

This post will show you how to add custom fields to your Devise registration form in Rails 5. For this example, we’ll add a name field.

  1. Make sure you’ve added Devise, generated its views, and migrated your custom fields.
# generate Devise views
rails generate devise:views

# add custom fields
rails g migration AddNameToUsers name:string
  1. Add a new controller at app/controllers/registrations_controller.rb. Make sure it inherits from Devise::RegistrationsController, and include your form fields in sign_up_params.
class RegistrationsController < Devise::RegistrationsController


def sign_up_params
params.require(:user).permit(:email, :password, :name)
  1. Let’s tell Devise to use this controller. In config/routes.rb:
devise_for :users, :controllers => {
registrations: 'registrations'
  1. Add your field to app/views/devise/registrations/new.html.erb.
<div class="field">
<%= f.label :name %>
<%= f.text_field :name %>

That’s all there is to it. You’ve added a custom field to your Devise registration form. And if you want to allow the user to edit this value too, you can add an account_update_params method to your Registrations Controller and customize app/views/devise/registrations/edit.html.erb.

About the author

I'm Mark Thomas Miller, a full stack engineer and designer currently working at ConvertKit. (We're hiring!) People like Arnold Schwarzenegger, Lindsey Stirling, and Tim Ferriss use features I've built to connect with their fans. I'm currently geeking out about Svelte, mechanical keyboards, and minimalist UI design, and replaying Ocarina of Time.