/ Authentication / Authentication with Devise

Devise gem link : https://github.com/plataformatec/devise

Install Devise Gem

  • Edit Gemfile
    gem 'devise'
  • Run the generator
    rails generate devise:install
  • Edit config/environments/development.rb
    config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
  • Add flash message at application.html.erb
    <p class="notice"><%= notice %></p>
    <p class="alert"><%= alert %></p>
  • Edit migration file (…_devise_create_users.rb)
    t.string :first_name, null: false, default: ""
    t.string :last_name, null: false, default: ""
  • Run migration
    rake db:migrate
  • Setup log in & Log out logic
    <% if user_signed_in? %>
       <%= link_to "Setting", edit_user_registration_path, :class => "btn btn-primary" %>
       <%= link_to "Log out", destroy_user_session_path, :class => "btn btn-danger" %>
    <% else %>
       <%= link_to "Sign in", user_session_path, :class => "btn btn-success" %>
       <%= link_to "Sign up", new_user_registration_path, :class => "btn btn-primary" %>
    <% end %>

No video for this post.

by ryzalyusoff