felipekk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Nov-10 08:45 UTC
children of childrens?
Hi all! I''m working on a role based auth system. Users have roles, roles have role_items which enable access to a controller/action pair. So: User -has_and_belongs_to_many :roles Role -has_and_belongs_to_many :users -has_many :role_items RoleItem -belongs_to :role so, using "user = User.find(1)", I can access his roles on "user.roles" and do something like "user.roles.each do |role|" to go trough all roles a given user has. I would like to know if I can go 2 levels down and do something like "user.roles.role_items.each do | role_item|". This would help me simplify this: user.roles.each do |role| role.role_items.each do |role_item| if role_item.controller == params[:controller] and role_item.action == params[:action] auth = true; end end end I tried doing that but rails told me that "role_items" was not defined for "user.roles". Also, if you have any tip on the whole role based auth system, I would love to hear your thoughts. Thanks! --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---