# routes.rb match "/:space_type/:id", :to => "spaces#show", :as => :space_type # linking link_to "My space", space_type_path(@space.space_type, @space.id)
which will generate these URLs: /bars/123 , /clubs/1 ... any space_type you have
And it looks like STI wold makes this work a little cleaner;)
UPD
You can also add restrictions to prevent some collisions:
match "/:space_type/:id", :to => "spaces#show", :as => :space_type, :constraints => { :space_type => /bars|clubs|hotels/ }
And yes, itβs a good idea to put this route at the bottom of all other routes.
You can also wrap it as an assistant (and rewrite your default space_url ):
module SpacesHelper def mod_space_url(space, *attrs)
source share