Note that this blog post has been archived. Information may be out of date or incorrect.

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 => /[^\/]*/

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