Rails 3 Routing Parameters with Dots

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 following parameters being passed:

{ :search => "bar", :format => "baz" }

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

match "/foo/:search", :constraints => { :search => /[^\/]*/ }

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:

match "/foo/:search", :search => /[^\/]*/

 

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

match "/foo/:search", :search => /.*/

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.

The bright future(s) of Scala programmers

The Scala library is pretty extensive, and I’ve only recently (about 4 months ago) started programming in Scala, so I really haven’t seen much of it yet. I was inspired to write a little something on the different Future-types available in Scala when I read this question on Stackoverflow, and while researching the topic I really learned a lot about Futures and the Scala library in general.

Continue reading