Ruby on rails Rails-如何按日期查询数据库
这听起来非常简单,但我无法让它工作(rails新手) 我要做的是使用Ruby on rails Rails-如何按日期查询数据库,ruby-on-rails,ruby,database,Ruby On Rails,Ruby,Database,这听起来非常简单,但我无法让它工作(rails新手) 我要做的是使用FooModel.find(:all,:order=>“date”)。但这不起作用(抛出一个错误)。为什么会这样 感谢您的帮助 Foo.order("date") # Ascending (oldest first) by default Foo.order("date DESC") # Descending (newest first) Foo.where(type: "bar").order("date D
FooModel.find(:all,:order=>“date”)
。但这不起作用(抛出一个错误)。为什么会这样
感谢您的帮助
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
查看本指南:非常感谢!我会尽快接受答案,所以我会让meHey@tehepicspineapple,我知道你的问题已经得到了回答,但仅供参考,你所拥有的将在Rails 2中工作。