Answer the question
In order to leave comments, you need to log in
How to make nested routes with one model?
Hello everyone, I'm a little new to rails. I have a "Page" model, I needed to make a tree of pages and sub-pages, i.e. one root page can have several subpages, in turn subpages can also have subsubpages, and so on ad infinitum. I achieved this with the "ancestry" gem.
Also, with the help of the additional "slug" field and the "to_param" method, I made it so that in the URL instead of the page ID there was its Name.
My problem is that all pages have a URL like: "/page-1-2" or "/page-1-2-1" instead of "/page-1/page-1-2" or "/page- 1/page-1-2/page-1-2-1" respectively.
What do I need to do or write in routes to get such nested URLs'
Answer the question
In order to leave comments, you need to log in
"/page-1/page-1-2/page-1-2-1" - such an attachment turns out to be superfluous, the last element already contains pointers to all the previous ones, maybe it's still worth leaving it as it is with one level?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question