0

这听起来非常简单,但我无法让它工作(rails newbie)。

我想做的是使用FooModel.find(:all, :order => 'date'). 然而这不起作用(引发错误)。为什么是这样?

任何帮助表示赞赏!

4

1 回答 1

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

于 2013-06-25T23:58:18.613 回答