Hi!

The problem:
You may have read the I18n-Guide (
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. 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

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

Regards from Hamburg, Germany

Johannes

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to