Answer the question
In order to leave comments, you need to log in
How to display products of all subcategories of a category?
Let's say I have a category "technology", and inside it subcategories ("computers", "phones", etc.). I want to display products from all subcategories of the 2nd category in localhost:3000/categories/2 .
Here is what I wrote for one subcategory, but how to display all products of all subcategories?
def show
category = Category.find_by(id: params[:id])
subcategories = category.subcategories.first
@products= subcategory.products
end
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question