Method: CanCan::ControllerAdditions#current_ability
- Defined in:
- lib/cancan/controller_additions.rb
#current_ability ⇒ Object
Creates and returns the current user’s ability and caches it. If you want to override how the Ability is defined then this is the place. Just define the method in the controller to change behavior.
def current_ability
# instead of Ability.new(current_user)
@current_ability ||= UserAbility.new(current_account)
end
Notice it is important to cache the ability object so it is not recreated every time.
358 359 360 |
# File 'lib/cancan/controller_additions.rb', line 358 def current_ability @current_ability ||= ::Ability.new(current_user) end |