Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not work with '-' or '/' in named route #25

Open
jensb opened this issue Oct 5, 2011 · 3 comments
Open

Does not work with '-' or '/' in named route #25

jensb opened this issue Oct 5, 2011 · 3 comments

Comments

@jensb
Copy link

jensb commented Oct 5, 2011

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!

@jensb
Copy link
Author

jensb commented Oct 6, 2011

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.

@kwi
Copy link
Owner

kwi commented Oct 6, 2011

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:
#25

@jensb
Copy link
Author

jensb commented Oct 7, 2011

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants