The Coding Journal ツ

Home

Impressum

x3ro’s Toolkit

By default, Rails 3 interprets a dot in a URL as a format specifier. For example, given the route

and the URL /foo/bar.baz , this would result in the following parameters being passed:

This may not be what you desire, so here is a quick workaround, using segment constraints :

The constraint for the :search parameter now matches anything but a slash, which includes the dot, and Rails will no longer interpret it as a format.

Update: The same effect can be achieved by using dynamic segments and the same regular expression, like this:

Update2: If you want to also ignore slashes within the URL, you can do the following:

With this matcher, if you’d open the URL “ /foo/los.tacos/son.deliciosos ” it would result in a search parameter with the value “ los.tacos/son.deliciosos “.

Thanks to this guy and this guy , who led me in the right direction.

This is a small update on a blog post which I wrote back on my old blog. Still need to find a way to move all those articles over to this blog without breaking the links.

By default, Rails 3 interprets a dot in a URL as a format specifier. For example, given the route match "/foo/:search" and the URL /foo/bar.baz, this would result in the...

Santhosh on November 25, 2011 at 3:03 pm said: Its works, thanks Reply ↓

Its works, thanks

RichieRich on January 18, 2012 at 12:39 pm said: Thanks for this Reply ↓

Thanks for this

Jonas on September 25, 2012 at 5:25 pm said: Nice man, Thanks. Do you know how to do it but with bars (/) ? Thanks! Reply ↓ Lucas Jenß on September 26, 2012 at 3:05 pm said: Updated the post to answer your question :) Reply ↓

Nice man, Thanks. Do you know how to do it but with bars (/) ? Thanks!

Lucas Jenß on September 26, 2012 at 3:05 pm said: Updated the post to answer your question :) Reply ↓

Updated the post to answer your question :)

Carlos Gottberg on March 12, 2013 at 5:04 am said: Works like a charm, thank you very much. Reply ↓

Works like a charm, thank you very much.

Andres Garcia on August 10, 2013 at 2:31 am said: Oh yeah it works perfectly for me, thanks for this. Reply ↓

Oh yeah it works perfectly for me, thanks for this.

desinghrajan on August 27, 2013 at 9:01 am said: Nice ! Thanks Reply ↓

Nice ! Thanks

Raghu on November 25, 2014 at 7:04 pm said: You are the bestest! you saved my time! what I love about Rails/Ruby is the community support, and you are part of this noble community! Keep it going! I can go on and on and on, because you saved me ‘HOURS’! hahaha! Cheers brother! Reply ↓

You are the bestest! you saved my time! what I love about Rails/Ruby is the community support, and you are part of this noble community! Keep it going! I can go on and on and on, because you saved me ‘HOURS’! hahaha!

Cheers brother!

Your email address will not be published. Required fields are marked *

Name *

Email *

Website

Comment

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>