[英]How to use Rails routing without resources, with use only ids
Description.描述。
I want filtering product on my site, but I won't use nested resources.我想在我的网站上过滤产品,但我不会使用嵌套资源。
Filtering has 4 level.过滤有4级。
For example,例如,
https://example.com/london/car/bmw/red https://example.com/london/car/bmw/red
or或者
https://example.com/:city/:category/:brand/:color https://example.com/:city/:category/:brand/:color
routes.rb路线.rb
get '/:one_id', to: 'categories#show', as: 'category_one'
get '/:one_id/:two_id', to: 'categories#show', as: 'category_two'
get '/:one_id/:two_id/:three_id', to: 'categories#show', as: 'category_three'
get '/:one_id/:two_id/:three_id/:four_id', to: 'categories#show', as: 'category_four'
Why I use names id like ":one_id", ":two_id" etc.?为什么我使用名称 id 像 ":one_id"、":two_id" 等?
Because ": one_id" may contain multiple objects (filters).因为“:one_id”可能包含多个对象(过滤器)。
For example,例如,
https://example.com/london/ https://example.com/london/
https://example.com/bmw/ https://example.com/bmw/
https://example.com/woman/ https://example.com/woman/
ie, ":one_id" may be city, category or sex (multiple entity) and ":two_id" may be category, brand or color, etc.即,“:one_id”可以是城市、类别或性别(多个实体),“:two_id”可以是类别、品牌或颜色等。
Question:问题:
What are the best practices for organizing such routing?组织此类路由的最佳实践是什么?
Configuration:配置:
Ruby 2.5.1 Ruby 2.5.1
Rails 5.2.2.1导轨 5.2.2.1
You can use shallow
to avoid deep nesting resources in rails.您可以使用shallow
来避免在 rails 中深度嵌套资源。 You can read this tutorial to have more information.您可以阅读本教程以获取更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.