开发者

In Rails, How to parse a category and sub category url structure

开发者 https://www.devze.com 2023-01-27 17:13 出处:网络
Say I have my urls like: www.example.com/categories/category1/subcategory1 My database would have a table Categories:

Say I have my urls like:

www.example.com/categories/category1/subcategory1

My database would have a table Categories:

ID NAME parentID 1 category1 -1 2 subcategory1 1

So I would need to load both category ID 1 and 2 since that is what is being displayed.

I know my explanation isn't that clear, but I hope what I am after is!

OH, and how would this route be开发者_运维百科 setup, since there could be an unlimited # of category/subcategory/sub-subcateogry levels.


http://guides.rubyonrails.org/routing.html#nested-resources

Following convention over configuration:

Resources should never be nested more than 1 level deep.

The rest of those guides are a good read.

0

精彩评论

暂无评论...
验证码 换一张
取 消