目标是创建以下URL路由:
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
我有一系列地点已分为几类。每个位置可以属于1个类别,也可以属于1个位置,或者是根位置。
Category.rb
has_many :locations
Location.rb
belongs_to :category
has_ancestry
我已经考虑过将位置模型分为位置和子位置,但是它不够灵活,无法支持所有可能的位置。这将是理想的结构,但是我不确定它是否支持此类路由。
理想情况下,这些路线还支持通过宝石Friendly_Id使用use,但目前这些路线仅适用于Category模型。
如何使我的路线像这样工作?