# Plz test my patch for resources with path\_prefix with a variable

**URL:** <https://www.ruby-forum.com/t/plz-test-my-patch-for-resources-with-path-prefix-with-a-variable/177685>\
**Category:** Rails\
**Created:** [October 21, 2009, 11:40pm UTC](https://www.ruby-forum.com/t/plz-test-my-patch-for-resources-with-path-prefix-with-a-variable/177685 "2009-10-21T23:40:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![igelig](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/3be4f8/32.png) [@igelig](https://www.ruby-forum.com/u/igelig)\
**Post date:** [October 21, 2009, 11:40pm UTC](https://www.ruby-forum.com/t/plz-test-my-patch-for-resources-with-path-prefix-with-a-variable/177685/1 "2009-10-21T23:40:34Z")

</div>

Hi!

The problem:  
You may have read the I18n-Guide (  
[Rails Internationalization (I18n) API — Ruby on Rails Guides](http://guides.rubyonrails.org/i18n.html#setting-the-locale-from-the-url-params)).  
It says, that the usual way to provide the locale is in the URL, like  
[example.com/en/books/2](http://example.com/en/books/2). 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:  
[https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/3394-polymorphic\_url-fails-to-generate-routes-with-path\_prefix-with-a-variable](https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/3394-polymorphic_url-fails-to-generate-routes-with-path_prefix-with-a-variable)

I hope, you’ll find this patch useful and it gets accepted into rails  
soon.

Regards from Hamburg, Germany

Johannes

---

<div class="post-metadata">

**Author:** ![igelig](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/3be4f8/32.png) [@igelig](https://www.ruby-forum.com/u/igelig)\
**Post date:** [October 22, 2009, 1:52pm UTC](https://www.ruby-forum.com/t/plz-test-my-patch-for-resources-with-path-prefix-with-a-variable/177685/2 "2009-10-22T13:52:24Z")

</div>

Hi friends,

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

Thanks  
Bava
