Here is my method
def categories
@categories = {}
cat = Category.includes(:sub_categories).where('categories.status = ?', true).order(:id)
cat.each do |category|
category.sub_categories.each do |sub_category|
@categories[category.name] = { name: sub_category.name }
end
end
end
What I am trying to do is
Assume my category.name is mobile phones and my sub_category.name will have list of mobile phone brands. But my above method prints one sub category only because the name is variable but how to create nested hash.
Any other proper method of doing this