Method: CanCan::ControllerAdditions#current_ability

Defined in:
lib/cancan/controller_additions.rb

#current_abilityObject

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()
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