【发布时间】:2011-08-22 10:25:30
【问题描述】:
我有一个类别模型。
attr_accessible :name, :parent, :tags, :active, :image
样本数据类似于
"Bakery",null,"bakehouse, baker, bakeries, bakers, bakery, bakeshop, biscuit factory, boulangerie, bread bakery, bread, cake bakery, cake topper, cake toppers, cake, cakes, confectionery, cook shop, pastry kitchen, pastry shop, pastry, patisserie, wedding cake", 1, null
"Beauty & Makeup",null,"makeup, ", 1, null
执行@categories = Category.all 为我提供了包含所有字段的所有类别,现在我想创建一个包含标签和类别名称的数组。数组数据应该是这样的
[["Bakery", "bakehouse"]
["Bakery", "baker"]
["Bakery", "bakeries"]
["Bakery", "bakers"]
["Bakery", "bakery"]
.....
["Beauty & Makeup", "makeup"]]
如何做到这一点?
【问题讨论】:
标签: ruby-on-rails arrays activerecord