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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
use request.subdomains to know the city param On Jan 2, 5:24 pm, Nicolas Blanco <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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. > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Peter De Berdt
2008-Jan-03  10:13 UTC
Re: Dynamicaly generate routes with a given subdomain ?
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:
> use request.subdomains to know the city param
>
> On Jan 2, 5:24 pm, Nicolas Blanco
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
> wrote:
>> 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?
Best regards
Peter De Berdt
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---