Hey Karel, I'd happily +1 on that ticket :)
But I can not find any code or patch on the ticket, so what would I +1 on? Just the request? IIRC the resource_fu plugin solves this kind of thing by "anchoring" positioned arguments on the right side, instead of the left (like Rails does it by default). http://www.artweb-design.de/2007/5/13/concise-localized-rails-url-helpers-solved-twice This won't handle "old-school", non-named urls though using the :controller => 'foo', :action => 'bar' syntax, or will it? On 24.10.2008, at 11:51, Karel Minarik wrote: > I did some further digging, and can confirm that the only (?) problem > so far lies in the order, in which the params in routes are filled, > precisely as Iain writes. > > When you have this route definition: > > map.resources :books, :path_prefix => '/:locale' > > Routes like `books_path`, `new_book_path`, etc work great, > `book_path(1)` etc throw an exception, because the ID (1) gets filled > into :locale and the :id is blank. > > When you call the helper like this: `book_path(I18n.locale, 1)`, > everything works fine and you get: > > '/en-US/books/1' > > If anyone is interested in this being fixed, and having the option to > transparently fill the locale in your routes, please visit the ticket > page http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1251 > and add your +1s and comments. > > Karel > > On Oct 22, 11:19 pm, Karel Minarik <[EMAIL PROTECTED]> wrote: >> Yes, indeed it behaves precisely like you describe, Iain. (I've tried >> on a sample app -- one question, where do you define >> `default_url_options`? I did in ApplicationController.) >> >> Routes like `books_path` or `new_book_path` work perfect, but not any >> route with params. >> >> If this would work, it would be *awesome*, because it's so >> transparent... I don't know nothing about routing internals as well, >> so we are in the hands of Destiny on this one? :) >> >> Best!, >> >> Karel >> >> Iain Hecker wrote: >>> Hi, >> >>> I'm sorry, I forgot all about it... Let's recap: >> >>> The problem is that Rails assigns non-hash objects to the first >>> variables in the route and only after that the default_url_options >>> get >>> assigned. So if you have user_url(1) for routes like >>> "/:locale/users/:id" then 1 will be assigned to :locale, and after >>> that the default_url_options kick in. They want to set :locale to >>> "en-US", but there is no :locale left, so it appends it ?locale=en- >>> US. >>> Then it raises a routing error because :id hasn't been filled. >> >>> If you don't have :locale in front, then this method works really >>> nice. You'd get what google uses (foo/bar?hl=en). >>> But I want to add the locale in front! (/en/foo/bar) >> >>> I have been wandering on lighthouse and found this ticket: >>> http://rails.lighthouseapp.com/projects/8994/tickets/22-default_url_o >>> ... >> >>> I don't know enough about the routing and url generation to solve >>> this, so I made a ticket: >>> http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/12 >>> ... >> >>> Iain >> >>> On Wed, Oct 22, 2008 at 18:51, Karel Minarik >>> <[EMAIL PROTECTED]> wrote: >> >>>> Hi, >> >>>> a while ago Iain mentioned the "default_url_options" method in >>>> Rails, >>>> which could be just what we need for preserving locale in URLs >>>> (thus >>>> being restafarians! :) >> >>>> Have you looked into any further, Iain? Has anybody else? It really >>>> looks like this would be perfect & transparent solution. >> >>>> Here are the docs: >> >>>> http://www.railsbrain.com/api/rails-2.1.0/doc/index.html?a=M000494&na >>>> ... >> >>>> Karel >> >>>>> From: "Iain Hecker" <[EMAIL PROTECTED]> >>>>> Date: Oct 3, 3:50 pm >>>>> Subject: Am I doing it right? (translating my first app) >>>>> To: rails-i18n >> >>>>> ... >> >>>>> Rails seems to have an answer to it, called >>>>> default_url_options[1], >>>>> but it doesn't seem to work. I've overwritten the method like >>>>> the api >>>>> tells me, but somehow it is ignored into generating the path. It >>>>> is >>>>> called, because it will break if I raise somthing in it. The >>>>> options >>>>> passed to it are what you'd expect (containing all the parameters >>>>> you'd pass to url_for) >> >>>>> Here's my method: >> >>>>> def default_url_options(options = {}) >>>>> { :locale => I18n.locale } >>>>> end > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "rails-i18n" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rails-i18n?hl=en -~----------~----~----~----~------~----~------~--~---
