DEV Community

Lam
Lam

Posted on

Devise Cheat Sheet

Reference

Customizing devise_for

devise_for :users,
  :path => "usuarios",
  :path_names => {
    :sign_in => 'login',
    :sign_out => 'logout',
    :password => 'secret',
    :confirmation => 'verification',
    :unlock => 'unblock',
    :registration => 'register',
    :sign_up => 'cmon_let_me_in' }
Enter fullscreen mode Exit fullscreen mode

Test helpers

include Devise::TestHelpers
https://github.com/plataformatec/devise/blob/1094ba65aac1d37713f2cba71f9edad76b5ca274/lib/devise/test_helpers.rb

sign_in @user
sign_out @user
Enter fullscreen mode Exit fullscreen mode

Devise_for magic

devise_for :users

    # Session routes for Authenticatable (default)
         new_user_session GET  /users/sign_in                    {:controller=>"devise/sessions", :action=>"new"}
             user_session POST /users/sign_in                    {:controller=>"devise/sessions", :action=>"create"}
     destroy_user_session GET  /users/sign_out                   {:controller=>"devise/sessions", :action=>"destroy"}

    # Password routes for Recoverable, if User model has :recoverable configured
        new_user_password GET  /users/password/new(.:format)     {:controller=>"devise/passwords", :action=>"new"}
       edit_user_password GET  /users/password/edit(.:format)    {:controller=>"devise/passwords", :action=>"edit"}
            user_password PUT  /users/password(.:format)         {:controller=>"devise/passwords", :action=>"update"}
                          POST /users/password(.:format)         {:controller=>"devise/passwords", :action=>"create"}

    # Confirmation routes for Confirmable, if User model has :confirmable configured
    new_user_confirmation GET  /users/confirmation/new(.:format) {:controller=>"devise/confirmations", :action=>"new"}
        user_confirmation GET  /users/confirmation(.:format)     {:controller=>"devise/confirmations", :action=>"show"}
                          POST /users/confirmation(.:format)     {:controller=>"devise/confirmations", :action=>"create"}
Enter fullscreen mode Exit fullscreen mode

As

as :user do
  get 'sign_in', :to => 'devise/sessions#new'
end
Enter fullscreen mode Exit fullscreen mode

Authenticated and unauthenticated routes

unauthenticated do
   root :to => 'home#index'
end

authenticated do
  root :to => 'dashboard#index'
end
Enter fullscreen mode Exit fullscreen mode

Migration helpers

create_table :users do |t|
  t.database_authenticatable
  t.confirmable
  t.recoverable
  t.rememberable
  t.trackable
  t.timestamps
end
Enter fullscreen mode Exit fullscreen mode

Routing

Model options

class User < ActiveRecord::Base
  devise :database_authenticatable,
    :registerable,
    :confirmable,
    :recoverable,
    :rememberable,
    :trackable,
    :validatable
end
Enter fullscreen mode Exit fullscreen mode

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay