Periods in parameter


#1

I have a tag cloud going and a route defined like so:

map.connect ‘tags/:id’, :controller => “tag”, :action => “browse”

Works great, except when the phrase has a period in it (like “Web
2.0”) Then I get a 404, presumably because Rails is interpreting that
as a file name and an extension. I have wrapped CGI::escape around it
but that doesn’t seem to affect periods. What’s the best way to
handle this?


#2

On Apr 10, 2009, at 8:53 AM, Ian wrote:

I have a tag cloud going and a route defined like so:

map.connect ‘tags/:id’, :controller => “tag”, :action => “browse”

Works great, except when the phrase has a period in it (like “Web
2.0”) Then I get a 404, presumably because Rails is interpreting that
as a file name and an extension. I have wrapped CGI::escape around it
but that doesn’t seem to affect periods. What’s the best way to
handle this?

I had a route where the :id could contain digits and/or a period.
This worked for me.

:requirements => { :id => %r([-\d.]+) }

Tweak that to allow your other characters and you should be all
right. However, in my case the full route was /foo/:id/:bar so maybe
having it in the middle makes a difference.

Good luck!