5

我做错了什么,从这个命令给了我一个空白数组?

Item.where(:load_date => Date.today + 2)

这是我的 Rails 控制台:

.9.3-p194 :024 > Item.first.load_date
Item Load (0.3ms)  SELECT "items".* FROM "items" LIMIT 1
=> Fri, 24 May 2013 
1.9.3-p194 :025 > Item.where(:load_date => Date.today + 2)
Item Load (0.5ms)  SELECT "items".* FROM "items" WHERE "items"."load_date" = '2013-05-24'
=> []
1.9.3-p194 :026 > Item.first.load_date == Date.today + 2
Item Load (0.3ms)  SELECT "items".* FROM "items" LIMIT 1
=> true 

商品型号:

... 
#  load_date       :date
...

class Item < ActiveRecord::Base
attr_accessible :bt_num, :dept, :formula, :item_code, :load_date, :prod_comments, :qc_comments, :qc_tech, :qty_in_kg, :qty_in_liters, :rm_ok_by, :series, :status, :time_to_produce, :vat
...
4

1 回答 1

1

试试这些

Item.where(:load_date => (Date.today + 2).strftime)
  or 
Item.where("Date(load_date) =?", (Date.today + 2).strftime)
于 2013-05-22T08:58:13.390 回答