Forum: Ruby on Rails periods in parameter

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C01f0b3db2e2548c7fd7de4052302925?d=identicon&s=25 Ian (Guest)
on 2009-04-10 17:54
(Received via mailing list)
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?
2505b282d57c29be797dc35b245adb4c?d=identicon&s=25 Philip Hallstrom (Guest)
on 2009-04-10 18:20
(Received via mailing list)
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!
This topic is locked and can not be replied to.