Created
November 15, 2011 19:47
-
-
Save jonpaul/1368102 to your computer and use it in GitHub Desktop.
uninitialized user?
This file contains hidden or 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, options = {}) | |
user ? user_rules : guest_rules | |
end | |
def user_rules | |
user.roles.each { |role| exec_role_rules(role) if user.roles.include? role } | |
default_roles | |
end | |
def exec_role_rules(role) | |
meth = :"#{user.role}_rules" | |
send(meth) if respond_to? meth | |
end | |
def admin_rules | |
can :manage, :all | |
end | |
def boss_rules | |
can :manage, :all | |
end | |
def exporter_rules | |
end | |
def member_rules | |
end | |
def guest_rules | |
can :read, Pages | |
can :create, Organization | |
can :create, User | |
end | |
end |
This file contains hidden or 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
undefined local variable or method `user' for #<Ability:0x007fd291ff1228> | |
Rails.root: /Users/derek/glide_projects/mdm | |
Application Trace | Framework Trace | Full Trace | |
app/models/ability.rb:10:in `user_rules' | |
app/models/ability.rb:6:in `initialize' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment