Please test my Rails patch for I18n resources like /:locale/articles/:id


The problem:
You may have read the I18n-Guide (
i18n.html#setting-the-locale-from-the-url-params). It says, that the
usual way to provide the locale is in the URL, like
books/2. This route would look like:

map.resources :books, :path_prefix => '/:locale'


This solution has currently one rather big *downside*. Due to the
_default_url_options_ implementation, you have to pass the :id option
explicitly, like this:

link_to 'Show', book_url(:id => book)

and not depend on Rails’ magic in code like

link_to 'Show', book.

Actually this is not a problem of default_url_options, but of
polymorphic_url, which is utilized by link_to in the example. It
generates the book_url and passes an array into the generated route.
This array has only one item, the book id. book_url tries to fill in
the id into the first parameter of the url, which is the locale
(/:locale/books/:id), which leaves the :id unsatisfied, raising an

The solution:
With my patch, polymorphic_url will pass an hash instead of an array
to the generated route. It may look like {:id => 2}. It works also
with nested resources: e.g.: {:author_id => 3, :id => 2}

The patch:
I've created a patch for Rails 3 and Rails 2-3-stable and put them in
a ticked on lighthouse:

I hope, you'll find this patch useful and it gets accepted into rails

Regards from Hamburg, Germany

PS: The guide how to test patches is here: