0

我有一个表 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

有什么建议会导致错误,或者如何实现?

4

1 回答 1

0

让 Rails 为您完成工作:

scope :needs_maintain, -> (day_count) { where('last_mnt > ?', day_count.days.from_now) }

然后调用它:

MntItem.needs_maintain(20)
于 2013-07-13T00:25:17.463 回答