Dynamicaly generate routes with a given subdomain?

my problem seems simple but I don’t manage to find a simple solution…

I would like my URLs to look like :


example :

My routes have this route :

map.building ‘building/:id’, :controller => ‘buildings’, :action =>

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


use request.subdomains to know the city param

On Jan 2, 5:24 pm, Nicolas B. [email protected]

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)

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 = ?”,

On 03 Jan 2008, at 10:59, blj wrote:

two parameters : city and builing_name?
Best regards

Peter De Berdt

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs