Supposing I have 3 tables: Users, Roles and UserRoles. I can fetch the user_roles in the request: users/1/user_roles but what if I want to fetch the roles of a user such as: users/1/roles.
My relation is as follows:
has_many :roles, :through => :user_roles
Is it possible?
The relation in your model has no direct relevance to the url you go to. You need to replicate your existing behaviour for
routesrather thanuser_routesby either adding a new action or new controller and creating new views etc.At the moment you probably have either:
user_routesin theUsersControllerindexin theUserRoutesControllerSo either:
routesin theUsersControllerRoutesControllerwith an index action.Regardless to which method you are using, in your action set your instance variable to
user.rolesinstead ofuser.user_roles.You can then write whatever view code you need.