Skip to content

Instantly share code, notes, and snippets.

@hopsoft
Created March 15, 2012 04:49
Show Gist options
  • Save hopsoft/2041958 to your computer and use it in GitHub Desktop.
Save hopsoft/2041958 to your computer and use it in GitHub Desktop.
Ability 2 - cancan abstract resource authorization
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new
resourceful_actions = [
:index,
:show,
:new,
:create,
:edit,
:update,
:destroy
]
can :index, [Array, ActiveRecord::Relation] do |list|
list.first.is_a?(User) && (list.map(&:id) - user.associates.map(&:id)).empty?
end
cannot resourceful_actions, User
can :update, User, :id => user.id
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment