为什么我的控制器在 rails 4 上更改为 postgres 后无法工作?

why my controller dont work since changing to postgres on rails 4?

我在 rails 4 开始开发我的网站,基本上使用 RoR sqlt3 附带的数据库,我想在数字海洋服务器上将我的网站投入生产,但他们使用 postgres.. 现在我想这个将以与我开始时相同的方式工作。但现在我收到错误

(错误)

PG::DatatypeMismatch: ERROR: argument of WHERE must be type boolean, not type timestamp without time zone LINE 1: SELECT "videos".* FROM "videos" WHERE (created_at ) ORDER B... ^ : SELECT "videos".* FROM "videos" WHERE (created_at ) ORDER BY cached_votes_up DESC, created_at DESC

(控制器)

def index
        @videos = Video.all.order("cached_votes_up DESC, created_at DESC")



        @items = Video.order("cached_votes_up DESC, created_at DESC").where("created_at ", Time.zone.now.beginning_of_day)

        @items_by_day = @items.group_by { |t| t.created_at.beginning_of_day }
        @topvideo = Video.order("cached_votes_up DESC, created_at DESC").where("created_at >= ?", Time.zone.now.beginning_of_day)
    end

(查看)

<% @items_by_day.sort.reverse.each do |day, items| %>

            <div class="row">
            <h1><%= day.strftime("%d %B %Y") %></h1>

                <div class="topAd">
    <center>
        <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- responsive -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-1876888588409540"
     data-ad-slot="6100356041"
     data-ad-format="auto"></ins>
        <script>
            (adsbygoogle = window.adsbygoogle || []).push({});
        </script>
    </center>
</div>



            <% for a in items %>

            <div class="videothumb col-xs-12 col-sm-4">


                <div class="" style="
    background-size: 100% 100%;
    height: 240px;
    -webkit-border-radius: 10px;
    -moz-border-radius: 10px;
    border-radius: 10px;
    overflow: hidden;">

                    <%= link_to  a do %>
  <div style="background: rgba(0,0,0, 0); width:100%; height: 85%;z-index:1000; position:absolute; top:0;"></div> 
<% end %>

                    <iframe width="100%" height="100%" src="https://www.youtube.com/embed/<%= a.url %>" frameborder="0" allowfullscreen></iframe>

                    </div>
                <div class="col-xs-12">
                <h3>
                    <%= link_to a.title, a %> </h3>
                </div>
                <div class="col-xs-6">
                <h2><%= a.artist %></h2>

                </div>
                <div class="col-xs-6">

                    <div style="text-align:right">
                        <%= link_to like_video_path(a), method: :put, class: "" do %>
                            <span class="glyphicon glyphicon-chevron-up">
                                <%= a.get_upvotes.size %>
                        <% end %> 
                        <%= link_to dislike_video_path(a), method: :put, class: "" do %>
        <span class="glyphicon glyphicon-chevron-down">
        <%= a.get_downvotes.size %>
      <% end %>

                    </div>
                </div>



            </div>
            <% end %>

            </div>


<% end %>

您的其中一个 where 子句缺少为 created_at 分配的值。

我相信这条线:

@items = Video.order("cached_votes_up DESC, created_at DESC").where("created_at ", Time.zone.now.beginning_of_day)

应替换为:

@items = Video.order("cached_votes_up DESC, created_at DESC").where("created_at >= ? ", Time.zone.now.beginning_of_day)