Last active
December 23, 2015 11:19
-
-
Save gavingmiller/6627231 to your computer and use it in GitHub Desktop.
A snapshot of PetroFeed's authorization code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Ability | |
include CanCan::Ability | |
def initialize(user) | |
@user = user || User.new # guest user (not logged in) | |
authorize_payment_limits | |
# Other access code | |
end | |
private | |
def authorize_payment_limits | |
if follow_limit_reached? | |
cannot :follow, Well | |
else | |
can :follow, Well | |
end | |
end | |
def follow_limit_reached? | |
!@user.pro? && @user.follow_count >= FOLLOW_LIMIT | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Really clean and well thought out. I love it.
One thing, can you simply do this instead: