Dynamicaly generate routes with a given subdomain ?

Hi, my problem seems simple but I don't manage to find a simple solution...

I would like my URLs to look like :

http://city.server.com/building/building_name

example : http://paris.server.com/building/louvre

My routes have this route :

map.building 'building/:id', :controller => 'buildings', :action => 'show'

Now, how can I generate the correct URL with the good subdomain with the two parameters : city and builing_name?

Thanks.

use request.subdomains to know the city param

For your own peace of mind, use the account_location plugin and then have a before_filter in your application controller:

before_filter :find_city

def find_city

@city = City.find_by_name(account_subdomain)

end

Then you can just use the associations you defined in your City model to get to the building:

@city.buildings.find(:first, :conditions => [“buildings.name = ?”, params[:building_name])