0

In Rails4 is it possible to have FriendlyId build out the complete url including categories and subcategories?

Example:
sitename/categories/6/subcategories/36/12

should be:
sitename/community/events/garage-sale-in-fresno
Community is the category, events is the subcategory
-OR-
sitename/nevada/las-vegas/woodshed-rib-shack-bbq
Nevada is the category, Las Vegas is the subcategory

I see how to create slugs for the individual listings, but it would be nice to have a way to create the complete url in 'friendly' format.

Any tips would be greatly appreciated.

jrfent
  • 13
  • 3

1 Answers1

0

You cannot achieve this using rails RESTful helpers, you need to define your own route:

get ':category_name/:subcategory_name/:id', to: '<your_controller>#<controller_action>'

Since this url signature will match many of your other routes, make sure it is placed after all the routes it can collide with (like /admin/login/failed), ideally at the end of the routes.rb file.

BroiSatse
  • 44,031
  • 8
  • 61
  • 86
  • Wow! That is not what I expected as a solution. I will experiment with it right away. Thanks for the great tip. – jrfent Dec 18 '15 at 02:38