On 15 March 2010 11:14, eugenio <[email protected]> wrote:
> a "User" has_and_belongs_to_many "Roles"
> a "Role" has_and_belongs_to_many "Rights"
>
> how can i relate Users and Rights? i would like something like
> @user.rights
> i know it can be done via SQL, but i don't know if there is a more
> rails-way to do this.
> any suggestion?
you can add a "rights" method to your user that collects up all the
rights for all of the User's roles:
def rights
roles.collect { |role| role.rights }.flatten.uniq
end
This gives you a starting point... you can memoize that method if you
access it a lot, or tweak it however suits...
HTH
Michael
--
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.