Answer the question
In order to leave comments, you need to log in
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 models: categories, subcategories, items. A category can have many (has_many) subcategories, subcategories have many items. Each model has its own rights.
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.
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 questionAsk a Question
731 491 924 answers to any question