AlwaysCharging
2010-Feb-19 03:04 UTC
a single Administrator without boolean column in User''s table?
Hi, I''m using Ryan Bate''s CanCan gem for my authorization (coupled with Authlogic for my authentication). In his railscast, he uses a boolean column in the database to define roles. However, my app is super simple and only needs one Administrator, and everyone else has the same permissions. How would I go about doing this? I thought of something like: def initialize(user) user ||= User.new if admin? can :manage, :all else can :read, :all can :create, Comment end end and then defining admin? as True if the current_user''s username was admin, but I cant figure out where to put this, much less how to accomplish this correctly. Any ideas? Or, maybe there''s even a better way? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Feb-19 04:41 UTC
Re: a single Administrator without boolean column in User''s
AlwaysCharging wrote:> Hi, I''m using Ryan Bate''s CanCan gem for my authorization (coupled > with Authlogic for my authentication). In his railscast, he uses a > boolean column in the database to define roles. However, my app is > super simple and only needs one Administrator, and everyone else has > the same permissions. How would I go about doing this?The way Ryan did -- with a boolean column.> > I thought of something like: > def initialize(user) > user ||= User.new > > if admin? > can :manage, :all > else > can :read, :all > can :create, Comment > end > end > > and then defining admin? as True if the current_user''s username was > admin, but I cant figure out where to put this, much less how to > accomplish this correctly. Any ideas?Don''t try to be clever with your usernames. There''s no reason to restrict the administrator name to being "admin", and no reason to restrict yourself to only having one administrator.> > Or, maybe there''s even a better way?There is. The way Ryan did it. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.