Setting up routes with formats and parameters that are domain names


This is on Rails 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/ - for when the user
wants a specific format
GET /somecontroller/ - for when the user requests
the default format

For the first path params should be {:action => ‘show’, :controller =>
‘somecontroller’, :id => ‘’, :format => ‘xml’}
but end up being {:action => ‘show’, :controller =>
‘somecontroller’, :id => ‘’}

For the second path params should be {:action => ‘show’, :controller
=> ‘somecontroller’, :id => ‘’} and work

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

How do you use :format when your URI contains domain names?

I’ve hit this issue while upgrading from Rails 2.1.2 to
Historically my site has just had two routes, one for the route with
format and one without.

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