module Dry::Ability::Controller::Mixin
Public Instance Methods
current_ability()
click to toggle source
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.
# File lib/dry/ability/controller/mixin.rb, line 66 def current_ability @current_ability ||= ability_class.new(current_user) end