Y
Y
Yuri2014-11-04 18:26:57
Ruby on Rails
Yuri, 2014-11-04 18:26:57

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

2 answer(s)
R
Renat Ibragimov, 2014-11-04
@Jazzis

"/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?

V
vsuhachev, 2014-11-04
@vsuhachev

Here . Describe a route with an asterisk parameter and then further parse what is included in this parameter

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question