TTQF

Tips Tricks & Quick Fix by @pietropassarelli.

Rails - installing Devise Gem

A quick step by step to install the devise user authentication gem in rails

1 min reading time

Rails girls devise guide

  1. add gem gem 'devise'

  2. bundle install bundle install

  3. add devise rails g devise:install

  4. ad config for development inf config/environments/development.rb add

    config.action_mailer.default_url_options = { :host => 'localhost:3000' }
```

5. ad flash notifications

in ``` app/views/layouts/application.html.erb``` above ``<%= yield %>``

`````erb
   <% if notice %>
      <p class="alert alert-success"><%= notice %></p>
    <% end %>
    <% if alert %>
       <p class="alert alert-danger"><%= alert %></p>
     <% end %
  1. add user model rails g devise user

  2. update db rake db:migrate

9.update/check routes i found that devise_for :users needs to be right under top of the page, like this:

    Rails.application.routes.draw do
    devise_for :users

    #some other routes code
    end

10.check if it works run server (rails s) and visit http://localhost:3000/users/sign_up you can check rails console (rails c) to see if the user has been created i.e. User.all.

  1. add links sign in/out/up see rest of rails guide to add links here