0

当我的应用程序被推送到 heroku 时,我在应用程序中遇到了一个奇怪的错误。该应用程序在我的本地机器上运行良好。我不知道是不是因为我在本地使用Mysql?

这是我得到的错误:

2012-07-24T17:14:52+00:00 app[web.1]: ActionView::Template::Error (PG::Error: ERROR:  argument of AND must be type boolean, not type integer
2012-07-24T17:14:52+00:00 app[web.1]: : SELECT COUNT(*) FROM "users" INNER JOIN "articles_users" ON "users"."id" = "articles_users"."user_id" WHERE "articles_users"."article_id" = 64 AND (1)):
2012-07-24T17:14:52+00:00 app[web.1]:     9:            <span>
2012-07-24T17:14:52+00:00 app[web.1]:     10:           <a data-action="like" data-id="<%= a.id %>" >
2012-07-24T17:14:52+00:00 app[web.1]:     11:           <%if user_signed_in?%>
2012-07-24T17:14:52+00:00 app[web.1]:     12:                   <%if a.likes.where(user_id = current_user.id).size == 0%>
2012-07-24T17:14:52+00:00 app[web.1]:     13:                           <%=image_tag("star.png", :width => "37", :height => "36", "data-action" => "star")%></a><span data-action="likes" style="vertical-align:10px; padding:8px;">
2012-07-24T17:14:52+00:00 app[web.1]:     14:                   <%else%>
2012-07-24T17:14:52+00:00 app[web.1]:     15:                           <%= image_tag("star-yellow.png", :width => "37", :height => "36", "data-action" =>"star")%></a><span data-action="likes" style="vertical-align:10px; padding:8px;">

这是我认为的代码:

<a data-action="like" data-id="<%= a.id %>" >
    <%if user_signed_in?%>  
        <%if a.likes.where(user_id = current_user.id).size == 0%>   
            <%= image_tag("star.png", :width => "37", :height => "36", "data-action" => "star")%></a><span data-action="likes" style="vertical-align:10px; padding:8px;">
        <%else%>
            <%= image_tag("star-yellow.png", :width => "37", :height => "36", "data-action" => "star")%></a><span data-action="likes" style="vertical-align:10px; padding:8px;">
        <%end%>

这里出了什么问题?先谢谢了!

4

2 回答 2

0

我变了

<%if a.likes.where(user_id = current_user.id).size == 0%> 

<%if !a.likes.include?(current_user)%>

现在它工作正常。

于 2012-07-24T19:06:59.103 回答
0

您应该像这样修改 where 方法。

a.likes.where(:user_id => :current_user.id)

不是

a.likes.where(user_id = current_user.id)

我认为这会奏效。

于 2012-07-24T18:08:02.217 回答