【问题标题】:Heroku PostgreSQL giving errors when using "<=" operator in where statementHeroku PostgreSQL 在 where 语句中使用“<=”运算符时出错
【发布时间】:2017-02-11 15:53:36
【问题描述】:

我正在创建一个带有过期特价商品的 Rails 应用程序。每次有人登录时,我都有一个 Def 查找已经过期的特价,然后删除。它在本地运行良好,但是当我将其部署到 heroku 时,出现此错误:

 ActiveRecord::StatementInvalid (PG::UndefinedFunction: ERROR:  operator does not exist: character varying <= numeric

和提示:

 HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.

这是我创建的定义。我在应用程序控制器中为 def 添加了一个 before_filter

    def check_expired
    time = DateTime.now.to_f.to_s
    @specials = Special.where("expires <= #{DateTime.now.to_f.to_s}")
    @specials.destroy_all
end

【问题讨论】:

    标签: ruby-on-rails postgresql heroku


    【解决方案1】:

    让 Rails 为您处理日期并像这样处理

    @specials = Special.where('expires <= ?', Time.zone.now)
    

    或者只是……

    @specials = Special.where('expires <= NOW()')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-15
      • 1970-01-01
      • 1970-01-01
      • 2021-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多