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_options-is-being-ignored-by-named-route-optimisation
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/1251-default_url_options-cant-be-used-with-named-routes
Iain
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?
> This "automagic" filling of locale `:prefix` in routes would be
> *really great* to have.
My translated_routes plugin[1] does this kind of filling on a
different way: it generates a helper for each localized route and
replaces the original one with a dinamic one which calls the
appropiate helper. An example will explain this better than my words:
- let's say you have generated a users_path helper, and two locales:
en_US and fr_FR
- the plugin generates two helpers: users_en_us_path and
users_fr_fr_path, with their corresponding locale's param value
- the plugin replaces the original users_path helper by some code
which calls users_en_us_path if the current locale is en-US and
users_fr_fr_path if the current locale is fr-FR.
Of course all this code generation and replacement is done after
routes generation (i.e: when the app starts), so there are no serious
performance penalties once the app is working.
If somebody is interested, I have just released a new branch[2] of the
plugin, now Rails2.2-oriented to support your I18n translation API,
which is *very cool* by the way: thanks so much guys! :)
Best regards,
--
Raul Murciano - Freelance Web Developer
http://raul.murciano.net
[1] http://github.com/raul/translate_routes/tree/master
[2] http://github.com/raul/translate_routes/tree/rails2.2