Reputation: 11107
I'm having a hard time understanding how CanCan works. I have the following model
class Ability
include CanCan::Ability
def initialize(user)
if user && user.email == "[email protected]"
can :access, :rails_admin # only allow admin users to access Rails Admin
can :dashboard # allow access to dashboard
end
end
end
When it comes to my rails_admin file in the initializers
folder
RailsAdmin.config do |config|
config.authorize_with :cancan
config.main_app_name = ['Pr', 'Admin']
config.current_user_method { } # auto-generated
end
I want to have one user to access the admins dashboard with the email "[email protected]", but how does CanCan know who is currently signed in at the time? Does it rely on a helper method I'm missing?
Upvotes: 2
Views: 1086
Reputation: 23949
CanCan uses a current_ability
method to supply the ability, and in that it uses current_user
. I know at least Devise has this method, other auth frameworks must commonly supply it too, not sure.
Upvotes: 4