A
A
Alexander Khorkov2018-09-11 14:46:02
Ruby on Rails
Alexander Khorkov, 2018-09-11 14:46:02

How to implement nested Ruby on Rails categories?

It is necessary to implement nested categories according to the following url pattern:
domain.com/:category/:subcategory/:item
And make it so that users can create a subcategory, but cannot create a category. (roles and access rights). For this task, I chose the cancancan gem.
Thank you.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
oh_shi, 2018-09-11
@oh_shi

3 models: categories, subcategories, items. A category can have many (has_many) subcategories, subcategories have many items. Each model has its own rights.

C
Crygo, 2018-09-11
@Crygo

How to implement?
You need to make it so that users can create a subcategory, but not be able to create a category. To do this, you need to create roles and access rights.

Z
Zaporozhchenko Oleg, 2018-09-12
@c3gdlk

ancestry gem. Many models are not convenient
for users to create a subcategory of a separate controller, it is easy to hang a cancan on it. In the same place, just in case, you raise an error if the parent_id did not come from the form.
In the form, you make a select without an empty value, or you put a category in the hidden field, or it will come from nested routes. It already depends on the interface

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question