Topic: Polymorphic Associations and RESTful design
Wanted to throw an idea out there, see if it would work.
I have an application in development which has users and locations. I'm using a polymorphic association for addresses.
has_many :addresses, :as => :addressable
has_one :address, :as => :addressable
belongs_to :addressable, :polymorphic => true
So far, so good, and it all works.
Now, in setting up a RESTful interface, I'd like to be able to do the following:
map.resources :users do |users|
users.resources :addresses, :name_prefix => 'user_'
map.resources :locations do |locations|
locations.resources :addresses, :name_prefix => 'location_'
This assumes 3 controllers, users_controller, locations_controller and addresses_controller.
Any potential gotchas in there, or should that work the way I expect, e.g.: