Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Rails - install Devise

Add devise gem

bundle add devise

Install Devise

rails generate devise:install

Generate views

rails generate devise:views

Generate User model

rails generate devise User

Migrate db

rails db:migrate

Add before action

In application controller:

    before_action :authenticate_admin

    def authenticate_admin
      unless user_signed_in? && current_user.admin?
        redirect_to root_path, alert: "You are not authorized to access this page"
      end
    end

Add flash messages

  • Create _flash.html.erb partial.