title: Rails: How to display category of products
body: <p>For my app i need to find category of the product. But don't know how to find it. Category has many sub-categories. Subcategory has many products. SubCategory and product are related through product_sub_category. Is there any way to know the category of product? Help!</p>
  
  <pre><code>Category model is:
    has_many :sub_categories
    accepts_nested_attributes_for :sub_categories, :allow_destroy =&gt; true
    has_many :products, :through =&gt; :sub_categories
  
  Sub-category model:
    attr_accessible :category_id, :description, :sub_category, :sub_category_url
    belongs_to :category
    has_many :product_sub_categories
    has_many :products, :through =&gt; :product_sub_categories
    has_one :photo, :as =&gt; :attachable, :dependent =&gt; :destroy  
    accepts_nested_attributes_for :photo, :allow_destroy =&gt; true
  
  ProductSubCategory
    belongs_to :product
    belongs_to :sub_category
    belongs_to :category
    attr_accessible :sub_category_id
    before_save :assign_category_id
  
  Product
    belongs_to :user
    has_many   :product_sub_categories
    has_many   :sub_categories, :through =&gt; :product_sub_categories
    has_many   :categories, :through =&gt; :sub_categories 
    accepts_nested_attributes_for :photos, :allow_destroy =&gt; true
    accepts_nested_attributes_for :product_sub_categories
  </code></pre>
  
  <p>I am showing Product page and want to display its category. How to do this? Let me know if i need to provide any other info.</p>