module Corral::ControllerAdditions
Public Class Methods
included(base)
click to toggle source
# File lib/corral/controller_additions.rb, line 25 def self.included(base) base.extend ClassMethods base.helper_method :can?, :cannot?, :current_ability if base.respond_to? :helper_method end
Public Instance Methods
can?(*args)
click to toggle source
Use in the controller or view to check the user's permission for a given action and object.
This simply calls “can?” on the current_ability. See Ability#can?
.
# File lib/corral/controller_additions.rb, line 60 def can?(*args) current_ability.can?(*args) end
cannot?(*args)
click to toggle source
Convenience method which works the same as “can?” but returns the opposite value.
# File lib/corral/controller_additions.rb, line 66 def cannot?(*args) current_ability.cannot?(*args) end
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.
Notice it is important to memoize the ability object so it is not recreated every time.
# File lib/corral/controller_additions.rb, line 52 def current_ability @current_ability ||= ::Ability.new(current_user) end