Open jensb opened 13 years ago
I found the problem: If you omit ":as => :something", i18n_routing will try to use the path as a function name. Which usually fails, because the path contains characters not allowed in function names, like '/', ':', '-', etc.
If I add unique :as parameters to all my routes, then it seems to work.
Hmm, I think you can't do it in rails itself apparently, so it will not be possible with i18n_routing too :/ Btw, no sure /products-name is better than /products/name in term of SEO (the last one give you a nice categorization) Also for the :name-:id, use the to_param method on your product object to achieve this trick.
You are welcome :)
2011/10/4 jensb < reply@reply.github.com>
Given this route:
ActionDispatch::Routing::SEPARATORS << "-" unless ActionDispatch::Routing::SEPARATORS.include?("-") match '/product-:name-:id' => 'products#show'
i18n_routing will throw an error
compile error /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/action_dispatch/routing/route_set.rb:161: syntax error, unexpected '-', expecting '\n' or ';'
I suspect this is because I am using different parameter separators than the default '/' and '.' (for SEO optimization).
How would I be able use this plugin in combination with such routes?
Thanks!
Reply to this email directly or view it on GitHub: https://github.com/kwi/i18n_routing/issues/25
The above example was just an example. :) For SEO purposes we don't use '/' because words after '/' will be interpreted as having a lower priority / hierarchy by search engines, which is not the case here (all words in the URL have the same priority).
# routes.rb
match '/product-:name-:id' => 'products#show', :as => :product_show
Your plugin works if I add ":as => ..." names to each route (which I don't have to do otherwise); and use the routes themselves in the YML file as lookup keys, instead of the route names, as in
# config/locales/de.yml
de:
named_routes_path:
'/product-:name-:id': '/produkt-:name-:id'
For easier route maintenance, I would have preferred something like
# config/locales/de.yml
de:
named_routes_path:
product_show: '/produkt-:name-:id'
because that would allow updating of the route in routes.rb without having to change all keys in the translations. Is it possible to add this feature?
Also, I would like to use ERB blocks in the locales file (because some of my routes in routes.rb are also created within loops). Would it be possible to add this feature?
Given this route:
i18n_routing will throw an error
I suspect this is because I am using different parameter separators than the default '/' and '.' (for SEO optimization).
How would I be able use this plugin in combination with such routes?
Thanks!