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

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)
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])

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

http://city.server.com/building/building_name
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