Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8025629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:13:37+00:00 2026-06-04T23:13:37+00:00

Im using Devise + CanCan and would like to redirect to my admin interface

  • 0

Im using Devise + CanCan and would like to redirect to my admin interface (generated by rails admin gem) IF its an ADMIN that logs in..

I customized the USER redirect to their respective profile by using the following :

class ApplicationController < ActionController::Base
  protect_from_forgery
  rescue_from CanCan::AccessDenied do |exception|
    redirect_to root_path, :alert => exception.message
  end
  def after_sign_in_path_for(resource)
    user_path(current_user)
  end

end

role.rb

class Role < ActiveRecord::Base
  has_and_belongs_to_many :users, :join_table => :users_roles
  belongs_to :resource, :polymorphic => true
end

ability.rb

class Ability
  include CanCan::Ability

  def initialize(user)
    user ||= User.new # guest user (not logged in)
    if user.has_role? :admin
      can :manage, :all
      can :access, :rails_admin
      can :dashboard 
    end

user.rb

class User < ActiveRecord::Base
    rolify
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
 .....
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T23:13:38+00:00Added an answer on June 4, 2026 at 11:13 pm

    I assume you have a boolean admin attribute on your User model.

    def after_sign_in_path_for(resource)
      if current_user.has_role? :admin
        rails_admin.dashboard_path
      else
        user_path(current_user)
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using devise gem to implement authentication in my Ruby On Rails application. Sometimes
I'm using Devise authentication gem with Rails. How to display the message from devise.en.yml:
I am using Devise gem and I want to change the redirect path after
I'm trying to get some basic authentication/authorization with devise/cancan with Rails. Rather than using
I'm using Cancan, Devise, Rails 3 for my ordering application. Each user has many
I'm using Devise and CanCan to create a backbone.js front-end and Rails 3.0.7 for
I'm using devise and cancan in a Rails 3.2 project. I have an event
I'm developing a Rails 3 app using Devise and CanCan. The app allows anonymous
I'm using the devise gem (1.4.2) and rails (3.0.7). I've got a view with
Using Devise, I would like to know if there is a way to remove

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.