0
力图打造一个漂亮的有序列表,我有我知道的工作,是它们在与会者类订单在Mongoid查询失败订购
def countries_ive_drunk
had_drinks.map {|drink| drink.beer.country }
end
def countries_ive_drunk_count
countries_ive_drunk.count
end
Knowning这些上述工作的方法。我创建了一个新的类,它想通过countries_ive_drunk_count
class Drinkers
include Mongoid::Document
def self.top_ten_drinkers
Participant.order_by([[:countries_ive_drunk_count, :asc]]).limit(10)
end
end
但是当这种向下传递到我的HAML文件,以获得参加,并责令列表:
get '/' do
@topdrinkers = Drinkers.top_ten_drinkers
haml :index
end
然后它不是” t正确排序。下面的代码会导致名称旁边有计数。数目不递增或递减,并且只按随机顺序(可能是为了用户订立的MongoDB
%ul
- @topdrinkers.all.each do |participant|
%li
= "#{participant.countries_ive_drunk_count} - #{participant.name}"
我缺少什么明显的(是不错的使用我的第一次红宝石,MongoDB的,mongoid, HAML ...投掷自己在深结束!)