Rails 1.2 routes and the dot “.”

Rails 1.2 came with great new features. One of them was the REST able applications. Other was the ability to serve results based on how the request was made. So you could send different results for controller/action.html, controller/action.xml or contoller/action.rss, for example. This one came with a price though: If you had any routes on your site that uses a dot (“.”), it will not work on rails 1.2.

Why is that? Well, the dot “.” is now a route separator, just like the slash “/”. But, of course, there’s a way to work around it if you don’t plan to use the dot for specific actions. Just place a :requirements => {:yourparam => /.*/} to your routes.rb. Here is an example:


# Here I could use an username like “john.smith” or “lys.cohen”, but not on Rails 1.2
map.connect “books/feed/:username”, {:controller => :book, :action => :book_feed}
After Rails 1.2:

# Now it works on Rails 1.2
map.connect “books/feed/:username”, {:controller => :book, :action => :book_feed, :requirements => { :username => /.*/}}

It worked great for me. And, best of all, it does not break the functionality, so you can use dots as they are intended to be used on other controllers and even actions on the same controller.

This tip was extracted from TextDrive Forums


~ by Dante Regis on May 22, 2007.

3 Responses to “Rails 1.2 routes and the dot “.””

  1. Just what I was looking for, thanks!

  2. thanks! had the same problem with 2.1, now it works!

  3. Awesome and easy fix 🙂 Thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: