Dan Van Derveer
2009-Jul-07 17:47 UTC
Setting up routes with formats and parameters that are domain names
## Configuration This is on Rails 2.3.2.1 running on ruby 1.8.4 ## in config/routes.rb map.somecontroller_show ''somecontroller/:id.:format'', :requirements => {:id => /\w[^\/?;]*/ }, :controller => ''somecontroller'', :action => ''show'', :conditions => { :method => :get } ## the problem :id for this controller is a domain name. The path to this route will look like this: GET /somecontroller/somehost.mydomain.com.xml - for when the user wants a specific format or GET /somecontroller/somehost.mydomain.com - for when the user requests the default format For the first path params should be {:action => ''show'', :controller => ''somecontroller'', :id => ''somehost.mydomain.com'', :format => ''xml''} but end up being {:action => ''show'', :controller => ''somecontroller'', :id => ''somehost.mydomain.com.xml''} For the second path params should be {:action => ''show'', :controller => ''somecontroller'', :id => ''somehost.mydomain.com''} and work properly. The problem is with this route I can not extract the format because it is getting matched by the :id regular expression. I could change the :id regular expression to be not greedy which will fix the first path but break the second one because it will extract ''com'' as the format. How do you use :format when your URI contains domain names? I''ve hit this issue while upgrading from Rails 2.1.2 to 2.3.2.1. Historically my site has just had two routes, one for the route with format and one without.