Skip to content

Instantly share code, notes, and snippets.

@jackdempsey
Created March 30, 2010 16:31
Show Gist options
  • Save jackdempsey/349266 to your computer and use it in GitHub Desktop.
Save jackdempsey/349266 to your computer and use it in GitHub Desktop.
class Ability
include CanCan::Ability
def initialize(user)
can [:read, :sort], Feature do |feature|
# below is turning into an idiom for me, one I sometimes forget about.
# thoughts on a better way to expose the "if we have an instance, use this check, else grant access to read/sort the Feature class"
(feature && feature.project.has_user?(user)) || true
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment