My table is:
| 1 | Electronics | Cameras
| 2 | Electronics | Computers
| 3 | Electronics | Mobile Phone
| 4 | Electronics | Sound & Vision
| 5 | Clothes | womens clothing
| 7 | Clothes | women shoes
| 8 | Clothes | women hand bags
| 9 | Clothes | Mens clothing
| 10 | Clothes | Kids clothing
I'm trying to get a link display on my index page like this:
**Electronics**
Computers
Mobile Phone
Sound & Vision
**Clothes**
womens clothing
women shoes
Mens clothing
How do i do this?
My model is like this:
class Category < ActiveRecord::Base
has_many :products
attr_accessible :division,:subdivision
end
class Product < ActiveRecord::Base
has_many :photos,:dependent => :destroy
has_many :line_items, :through => :product_id
belongs_to :merchant
belongs_to :category
attr_accessor :quantity
accepts_nested_attributes_for :photos, :line_items
Category table is the parent and product has a category_id. I want to display categories in the above manner, only if there are any products and my product model looks like this:
Once links display when I click on the link, I'm planning to show all the related products.
Can anyone guide me how to display the categories which have products?