Plz test my patch for resources with path_prefix with a variable


The problem: You may have read the I18n-Guide ( It says, that the usual way to provide the locale is in the URL, like But:

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 explicitely, 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 exception.

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 soon.

Regards from Hamburg, Germany


Hi friends,

How to increase the response speed rails application. Pls suggest some steps to improve the performance.

Thanks Bava