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.

有帮助吗?

解决方案

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!

其他提示

Solution with specs and correct edit\update etc. slugs here:

http://jasoncodes.com/posts/rails-3-nested-resource-slugs#solution

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top