Hiding a resource name in FriendlyID slug
-
15-06-2021 - |
Pergunta
I'm using FriendlyID to produce slugs for some of my models.
To use the example provided in the FriendlyID docs ( http://rubydoc.info/github/norman/friendly_id/master/frames ), my URLs currently look like this:
http://localhost:3000/cities/seattle/restaurants/joes-diner
Given that in my case, a city wouldn't have anything but restaurants, I'm looking for a way to remove the "restaurants" bit in the URL, so that it would look like this:
http://localhost:3000/cities/seattle/joes-diner
or if possible even
http://localhost:3000/seattle/joes-diner
What's the best way to achieve this - if it's at all advisable to do this? I can imagine that the last option might create some complications.
Solução
You can find the fix to your problem in http://guides.rubyonrails.org/routing.html#controller-namespaces-and-routing#controller-namespaces-and-routing
You can use :path => ""
for this task.
Regards!
Outras dicas
Solution with specs and correct edit\update etc. slugs here:
http://jasoncodes.com/posts/rails-3-nested-resource-slugs#solution