I''m pretty new to rails, but I''ve had many years programming in Java. What I''m looking to find is the rails way of implementing some clean way of controlling what the user sees based on the user''s role. The Rails Recipes book has a nice clean implementation of user roles and I''ve implemented that. What I want to avoid is stuff like <% if user.admin? %> show admin stuff <% else %> show normal user stuff <% end %> all over my code. I can think of a couple of ways to do it, but I feel like I''d be reinventing the wheel and someone certainly has cracked this nut and at least blogged it some where. I''ve tried some Google searches, but it''s a hard problem to define in few enough words to get good results. Anyone know of any good references for this problem? -- 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.
Well, the purpose of Helpers is to keep your views nice and DRY, so you could make some helpers with common code that comes up because of this, that takes a user. Your helpers still end up looking like this, though, so it''s not super ideal, but you''ve at least pushed the ugly down as far as possible. I haven''t found a better solution than that. On Wed, Jan 6, 2010 at 12:48 AM, Curtis Cooley <curtis.cooley-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> I''m pretty new to rails, but I''ve had many years programming in Java. > What I''m looking to find is the rails way of implementing some clean > way of controlling what the user sees based on the user''s role. > > The Rails Recipes book has a nice clean implementation of user roles > and I''ve implemented that. What I want to avoid is stuff like > > <% if user.admin? %> > show admin stuff > <% else %> > show normal user stuff > <% end %> > > all over my code. I can think of a couple of ways to do it, but I feel > like I''d be reinventing the wheel and someone certainly has cracked > this nut and at least blogged it some where. > > I''ve tried some Google searches, but it''s a hard problem to define in > few enough words to get good results. > > Anyone know of any good references for this problem? > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > > >-- 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.
david.t.rogers-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2010-Jan-07 00:13 UTC
Re: Factories, Authentication, and Roles, oh my!
You can use a gem called declarative_authorization to clean this up nicely. Its an implementation of rbac (role based access control for non security types), which I'm pretty sure is what you need, ... You can do: If has_role(:admin?) Show admin stuff -or- If permitted_to(:show, @stuff) Show admin stuff Sent via BlackBerry by AT&T -----Original Message----- From: Steve Klabnik <steve.klabnik@gmail.com> Date: Wed, 6 Jan 2010 16:54:34 To: <rubyonrails-talk@googlegroups.com> Subject: Re: [Rails] Factories, Authentication, and Roles, oh my! Well, the purpose of Helpers is to keep your views nice and DRY, so you could make some helpers with common code that comes up because of this, that takes a user. Your helpers still end up looking like this, though, so it's not super ideal, but you've at least pushed the ugly down as far as possible. I haven't found a better solution than that. On Wed, Jan 6, 2010 at 12:48 AM, Curtis Cooley <curtis.cooley@gmail.com>wrote:> I'm pretty new to rails, but I've had many years programming in Java. > What I'm looking to find is the rails way of implementing some clean > way of controlling what the user sees based on the user's role. > > The Rails Recipes book has a nice clean implementation of user roles > and I've implemented that. What I want to avoid is stuff like > > <% if user.admin? %> > show admin stuff > <% else %> > show normal user stuff > <% end %> > > all over my code. I can think of a couple of ways to do it, but I feel > like I'd be reinventing the wheel and someone certainly has cracked > this nut and at least blogged it some where. > > I've tried some Google searches, but it's a hard problem to define in > few enough words to get good results. > > Anyone know of any good references for this problem? > > -- > 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@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe@googlegroups.com<rubyonrails-talk%2Bunsubscribe@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > > >-- 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.
is there a way to combine those think with field-level security? i think i saw once a plugin, but didnt need it at that time. thx On Wed, Jan 6, 2010 at 7:13 PM, <david.t.rogers-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You can use a gem called declarative_authorization to clean this up nicely. > Its an implementation of rbac (role based access control for non security > types), which I''m pretty sure is what you need, ... You can do: > > If has_role(:admin?) > Show admin stuff > -or- > If permitted_to(:show, @stuff) > Show admin stuff > > Sent via BlackBerry by AT&T > > ________________________________ > From: Steve Klabnik <steve.klabnik-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > Date: Wed, 6 Jan 2010 16:54:34 +0300 > To: <rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > Subject: Re: [Rails] Factories, Authentication, and Roles, oh my! > Well, the purpose of Helpers is to keep your views nice and DRY, so you > could make some helpers with common code that comes up because of this, that > takes a user. > Your helpers still end up looking like this, though, so it''s not super > ideal, but you''ve at least pushed the ugly down as far as possible. I > haven''t found a better solution than that. > > On Wed, Jan 6, 2010 at 12:48 AM, Curtis Cooley <curtis.cooley-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> >> I''m pretty new to rails, but I''ve had many years programming in Java. >> What I''m looking to find is the rails way of implementing some clean >> way of controlling what the user sees based on the user''s role. >> >> The Rails Recipes book has a nice clean implementation of user roles >> and I''ve implemented that. What I want to avoid is stuff like >> >> <% if user.admin? %> >> show admin stuff >> <% else %> >> show normal user stuff >> <% end %> >> >> all over my code. I can think of a couple of ways to do it, but I feel >> like I''d be reinventing the wheel and someone certainly has cracked >> this nut and at least blogged it some where. >> >> I''ve tried some Google searches, but it''s a hard problem to define in >> few enough words to get good results. >> >> Anyone know of any good references for this problem? >> >> -- >> 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. >> >> >> > > > -- > 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. > >-- 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.