Authentication with Devise

Adds user authentication to your app using the Devise gem
Icons/chart bar
Used 2248 times
Created by
C Chris Oliver

Usage
Once you've finished running this template, make sure to add sign up and login links to your navigation.

<% if user_signed_in? %>
  <%= link_to "Account", edit_user_registration_path %>
  <%= link_to "Logout", destroy_user_session_path, method: :delete %>
<% else %>
  <%= link_to "Sign Up", new_user_registration_path %>
  <%= link_to "Login", new_user_session_path %>
<% end %>

Run this command in your Rails app directory in the terminal:

rails app:template LOCATION="https://www.railsbytes.com/script/X8Bsjx"
Template Source

Review the code before running this template on your machine.

def do_bundle
  # Custom bundle command ensures dependencies are correctly installed
  Bundler.with_unbundled_env { run "bundle install" }
end

run "bundle add devise"
do_bundle

rails_command "generate devise:install"

model_name = ask("What do you want to call your Devise model?")
attributes = ""
if yes?("Do you want to any extra attributes to #{model_name}? [y/n]")
  attributes = ask("What attributes?")
end

# We don't use rails_command here to avoid accidentally having RAILS_ENV=development as an attribute
run "rails generate devise #{model_name} #{attributes}"
Comments
Noumedem Simon Eric