这听起来非常简单,但我无法让它工作(rails newbie)。
我想要做的是使用FooModel.find(:all, :order => 'date')
。然而,这不起作用(抛出错误)。这是为什么?
感谢任何帮助!
答案 0 :(得分:0)
Foo.order("date") # Ascending (oldest first) by default
Foo.order("date DESC") # Descending (newest first)
Foo.where(type: "bar").order("date DESC").limit(10)
# Get the 10 newest Foo of type "bar".
Foo.where(type: "bar").order("date DESC").limit(10).to_sql
# SELECT "foos".* FROM "foos"
# WHERE "foos"."type" = 'bar'
# ORDER BY date DESC
# LIMIT 10
请查看本指南:http://guides.rubyonrails.org/active_record_querying.html