对于我的应用程序,我需要找到产品的类别。但是不知道怎么找。类别有许多子类别。子类别有很多产品。SubCategory 和 product 通过 product_sub_category 关联。有没有办法知道产品的类别?帮助!
Category model is:
has_many :sub_categories
accepts_nested_attributes_for :sub_categories, :allow_destroy => true
has_many :products, :through => :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 => :product_sub_categories
has_one :photo, :as => :attachable, :dependent => :destroy
accepts_nested_attributes_for :photo, :allow_destroy => 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 => :product_sub_categories
has_many :categories, :through => :sub_categories
accepts_nested_attributes_for :photos, :allow_destroy => true
accepts_nested_attributes_for :product_sub_categories
我正在显示产品页面并希望显示其类别。这该怎么做?如果我需要提供任何其他信息,请告诉我。