Im using Devise + CanCan and would like to redirect to my admin interface (generated by rails admin gem) if it has ADMIN that is logged in.
I configured USER redirect to my profile 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
user.rb
class User < ActiveRecord::Base rolify devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable .....
source share