Rails查询日期

时间:2011-08-16 23:23:27

标签: ruby-on-rails

我看到heroku中的当前错误(谁正在使用pgsql)

2011-08-16T23:18:58+00:00 app[web.1]: ActiveRecord::StatementInvalid (PGError: ERROR:  syntax error at or near "end"
2011-08-16T23:18:58+00:00 app[web.1]: LINE 1: ...".* FROM "deals" WHERE (start <= '2011-08-16' AND end > '201...
2011-08-16T23:18:58+00:00 app[web.1]:                                                              ^
2011-08-16T23:18:58+00:00 app[web.1]: : SELECT "deals".* FROM "deals" WHERE (start <= '2011-08-16' AND end > '2011-08-16')):
2011-08-16T23:18:58+00:00 app[web.1]:   app/helpers/deals_helper.rb:7:in `currently_active'
2011-08-16T23:18:58+00:00 app[web.1]:   app/controllers/users_controller.rb:11:in `home'

这是由

生成的
d = Deal.where(["start <= ? AND end > ?", today, today])

我仍然想继续在sqlite3上开发。但我希望这可以在pgsql上运行。有任何想法吗?

3 个答案:

答案 0 :(得分:0)

试试这个:

d = Deal.where(["start <= '?' AND end > '?'", today, today])

答案 1 :(得分:0)

我想是的:

d = Deal.where(["'start' <= ? AND 'end' > ?", today, today])

答案 2 :(得分:0)

???

d = Deal.where(['start <= ? AND end > ?', today, today])