Logo

dev-resources.site

for different kinds of informations.

Devise Cheat Sheet

Published at
5/14/2021
Categories
devise
cheatsheet
Author
hoanganhlam
Categories
2 categories in total
devise
open
cheatsheet
open
Author
11 person written this
hoanganhlam
open
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
devise Article's
30 articles in total
Favicon
Devise not accepting JSON Token
Favicon
Reset password mailer implementation in rails 7 api, devise_token_auth, and sendgrid-ruby.
Favicon
Ruby on Rails: Autenticação utilizando Devise + Keycloak
Favicon
How to Install Devise
Favicon
Warden of Hanami - hanami.rb basic authentication
Favicon
Devise raise validations error when new and old passwords are same
Favicon
Hooking in to Devise controller actions
Favicon
Rails 基礎 Part 06 -- devise でログインをした上で、API UT を叩く
Favicon
Using Devise and SendGrid to send confirmation email on rails app
Favicon
Omniauth without Devise
Favicon
Setting Up User Auth With React and Rails Minus The JWT Headache
Favicon
How to Backup Android Contacts to Mac Devices?
Favicon
Signout Users
Favicon
Rails 7 + Devise + Log out
Favicon
How to Add ToS Agreement Checkbox to Your Rails App using Devise?
Favicon
Multi-Factor Authentication for Rails with WebAuthn and Devise
Favicon
Omniauth + Devise + Rails Tutorial
Favicon
Rails 7.0.0alpha2, esbuild, tailwind and devise
Favicon
Devise: User + Profile
Favicon
Rails redirect user to the previous page after signup or login
Favicon
Devise-ing A Backend...
Favicon
Devise Cheat Sheet
Favicon
Rails Authentication with Devise
Favicon
Extending the default user devise
Favicon
Using Devise for User Auth
Favicon
install gem invisible_captcha with devise
Favicon
Adding a field to your sign-up form with Devise
Favicon
Declaring multiple sets of scopes for the same provider with Devise and OmniAuth in Rails
Favicon
Devise and JWT in Rails
Favicon
Customize Devise’s flash messages

Featured ones: