I am trying to setup the has_many :through scheme but am having some
difficulties.
The long story short I am building a simple ACL.
I have Users, Roles and Permissions. Below is what I started with for
associations.
class User < ActiveRecord::Base
has_and_belongs_to_many :roles
end
class Role < ActiveRecord::Base
has_and_belongs_to_many :users
has_and_belongs_to_many :permissions
end
class Permission < ActiveRecord::Base
has_and_belongs_to_many :roles
end
With this setup, everything was connected together and working fine.
I would like to setup users having permissions through roles.
I tried:
class User < ActiveRecord::Base
has_and_belongs_to_many :roles
has_many :permissions, :through => :roles
end
but that does not work. From what I have read, if I can get the
through to work, I should beable to do something like
@user.permissions.
How can I set this up so a user can have many roles, a role can have
many permissions, a role can have many users, and a user can have
permissions through roles?
Any suggestions would be very helpful.