Rails routing/polymorphism issue - how to model the following
Posted
by 46and2
on Stack Overflow
See other posts from Stack Overflow
or by 46and2
Published on 2010-06-06T01:48:12Z
Indexed on
2010/06/06
1:52 UTC
Read the original article
Hit count: 391
Hi all,
I have an app where a 'user' belong to a 'client' or a 'vendor' (and client and vendor has_many users). In the admin namespace, I want to administer these users - so an admin would choose a client or a vendor, then nav to that client's or vendor's users. My question is, short of making the user model polymorphic, how could I model/route this?
Here is what I have in terms of routing:
map.namespace :admin do |admin|
admin.resources :clients
admin.resources :vendors
end
I know I could do something like:
map.namespace :admin do |admin|
admin.resources :clients do |client|
client.resources :users
admin.resources :vendors do |vendor|
vendor.resources :users
end
end
But the above would definitely need me to treat the User as polymorphic.
I'm just wondering what you would recommend or what my options are.
Thanks.
© Stack Overflow or respective owner