2
我想创建一个由多少产品是在类别(标签)订购了简单的菜单Rails有很多通过关联如何按孩子数量排序?
像:
Television (10)
Toothpase (5)
Computer (3)
我的控制器:
def tags
@tags = Tag.all
end
我的看法:我的模特儿:
has_many :konkurrancers, :through => :tagsmenus
感谢唯一的问题是,这是错误的方向如何使命令ny DECS – 2011-04-30 23:47:50
如何创建计数器缓存列?我已经搜索了互联网,发现这个http://railscasts.com/episodes/23-counter-cache-column,但它不是rails 3 – 2011-04-30 23:50:12
我找到了一个解决方案如何扭转顺序:Tag.all.sort_by {| t | t.konkurrancers.count} .reverse – 2011-04-30 23:56:52