Intermediate TDD in Rails : Install and Configure Devise


Install and configure devise.


When a user registers and logs in to our site, we will present the different subscription plans they can choose from. This lesson will focus on devise installation and configuration. We will write tests and drive the implementation in the next lesson.


Step 1


gem 'devise' 

to Gemfile. Run bundle.

Step 2


$rails g devise:install

Step 3


config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }

to config/environments/development.rb

Step 4

Add :

  <p class="notice"><%= notice %></p>
  <p class="alert"><%= alert %></p>

to app/views/layouts/application.html.erb file. The layout file now looks like this:

<!DOCTYPE html>
  <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
  <%= csrf_meta_tags %>

   <p class="notice"><%= notice %></p>
   <p class="alert"><%= alert %></p>

<%= yield %>


Step 5

Copy devise views for customization.

$rails g devise:views

Step 6

Create the user model.

$rails g devise user

Step 7

Create the table.

$rake db:migrate


In this lesson we installed and configured devise to manage user accounts.

Related Articles

Create your own user feedback survey