我有一個表Mnt_Items,用於存儲在last_mnt中完成的上次維護的日期。此外,該表還存儲mnt_frequence中的維護之間的天數。 我要作出這樣的呈現需要維護所有項目的看法,但我得到的錯誤:如何在條件中設置日期的格式
SQLite3::SQLException: near "23": syntax error: SELECT "mnt_items".* FROM "mnt_items" WHERE (last_mnt > 2013-06-22 23:58:41 UTC)
我的模型和控制器如下:
class MntItem < ActiveRecord::Base
named_scope :needs_maintain, :conditions => "last_mnt > " + -20.days.from_now.to_s
end
class MntItemsController < ApplicationController
def index
@mnt_items = MntItem.needs_maintain
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @mnt_items }
end
end
任何建議是什麼原因造成的錯誤,或者如何實現?
您是否嘗試過封閉單引號(')內的日期值? – Ma3x
Gylaz給了我一個解決方案。謝謝 – Dajoh