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!