The goal is to create the following URL routes:
localhost:3000/category-1/location-1/
localhost:3000/category-1/location-1/sub-location-2
localhost:3000/category-1/location-1/sub-location-2/sub-location-3
I have a series of locations that have been split into categories. Each location can belong to 1 category, and can also belong to 1 location, or is a root location.
Category.rb
has_many :locations
Location.rb
belongs_to :category
has_ancestry
I have considered splitting my Location model into Location and SubLocation, but it's not flexible enough to support every location possible. This would be the ideal structure, but I'm not sure if it would support routes like these.
Ideally, the routes would also support use of slugs via the gem Friendly_Id, but currently these are only working for the Category model.
What can I do to get my routes to work like this?
get ':category/:location', to: 'locations#action1'
get ':category/:location/:sublocation', to: 'locations#action2'
get ':category/:location/:sublocation/:subsublocation', to: 'locations#action3'
see Rails Routing from the Outside In for more information