我一直在尝试用两个条件start
和end
日期时间进行简单的查询。
在开发模式下我没有任何问题,它似乎运行良好(SQLite)
但是在生产模式下我有以下错误:
ActionView::Template::Error (PG::Error: ERROR: syntax error at or near "end"
LINE 1: ...ions" WHERE (start >= '2013-01-30T10:12:24Z' AND end >= '20...
: SELECT COUNT(*) FROM "missions" WHERE (start >= '2013-01-30T10:12:24Z' AND end >= '2013-01-30T10:12:24Z')):
^
6: <li class="mission clearfix">
1: <h4 class="heading-sep"><%= t(".upcoming_missions")%></h4>
2: <div class="missions-timeline">
3: <ul class="mission-list">
app/views/users/show.html.erb:12:in `_app_views_users_show_html_erb___1717297229253226868_63256380'
7: <div class="mission-wrap clearfix">
4: <% if @upcoming_missions.any? %>
5: <% @upcoming_missions.each do |mission| %>
app/views/users/_mission_timeline.html.erb:4:in `_app_views_users__mission_timeline_html_erb__2786253018340202740_62779040'
在我的控制器中,我有以下查询:
@upcoming_missions = Mission.where("start >= ? AND end >= ?", Time.now, Time.now).order("created_at DESC")
@current_missions = Mission.where("start <= ? AND end >= ?", Time.now, Time.now).order("created_at DESC")
@past_missions = Mission.where("start <= ? AND end <= ?", Time.now, Time.now).order("created_at DESC")
我尝试了其他建议,包括.utc
以防 PG 读取时间与 SQLite 不同......但我不确定问题出在哪里。
谢谢您的帮助
奥雷连