4
임 고안 + 캉캉를 사용하여 로그인 할 ADMIN ..유증 관리자는
내가 사용자 리디렉션에 대한 사용자 정의의 경우 (관리자 보석 레일에 의해 생성) 내 관리 인터페이스로 리디렉션 싶습니다 리디렉션
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
.....
메신저 사용 캉캉은 @xnm – js111
(지금은 모든 관련 모델을 추가) 내 대답을 편집했습니다. –
붐! 감사합니다. – js111