Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails-如何按日期查询数据库_Ruby On Rails_Ruby_Database - Fatal编程技术网

Ruby on 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

这听起来非常简单,但我无法让它工作(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 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中工作。