我的表是:在Rails中显示数据库值?
| 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
我想获得一个链接显示我的索引页上是这样的:
**Electronics**
Computers
Mobile Phone
Sound & Vision
**Clothes**
womens clothing
women shoes
Mens clothing
我如何做到这一点?
我的模式是这样的:
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_id
。我想以上述方式显示类别,只有当有任何产品和我的产品型号如下所示时:
链接显示,当我点击链接时,我打算显示所有相关产品。
任何人都可以指导我如何显示有产品的类别?
这是一个视图问题。你能告诉我们你的视图/控制器文件是什么样子吗? – jason328 2013-03-25 02:05:32
我还没有创建视图。但在我的类别控制器看起来像这样,我看到我的show.html.erb中的数据。但我不知道如何显示它在我的主页index.html.erb pageclass CategoryController
user2067515
2013-03-25 02:08:28