You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 12, 2021. It is now read-only.
The Ability class and current_user method can easily be changed to something else.
# in ApplicationControllerdefcurrent_ability@current_ability ||= AccountAbility.new(current_account)end
Sometimes you might have a gem in your project which provides its own Rails engine which also uses CanCan such as LocomotiveCMS. In this case the current_ability override in the ApplicationController can also be useful.
# in ApplicationControllerdefcurrent_abilityifrequest.fullpath =~ /\/locomotive/@current_ability ||= Locomotive::Ability.new(current_user)else@current_ability ||= Ability.new(current_user)endend
If your method that returns the currently logged in user just has another name than current_user, it may be the easiest solution to simply alias the method in your ApplicationController like this:
classApplicationController < ActionController::Basealias_method:current_user,:name_of_your_method# Could be :current_member or :logged_in_userend
That's it! See Accessing Request Data for a more complex example of what you can do here.