2012-07-24 226 views
0

當我的應用程序被推送到heroku時,我得到一個奇怪的錯誤。該應用運行良好,我的本地機器。我不知道是否因爲我在本地使用Mysql?PG ::錯誤部署到heroku

以下是錯誤我得到:

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%> 

怎麼回事錯在這裏? 感謝先進!

回答

0

我改變

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

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

現在它工作正常。

0

你應該像這樣修改where方法。

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

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

我認爲這會工作。

+0

沒有。這導致它搜索錯誤的表,它搜索用戶表而不是連接表articles_users 'Mysql2 ::錯誤:'where子句'中的未知列'users.user_id':SELECT COUNT(*)FROM' users' INNER JOIN'articles_users' ON'users'.'''''articles_users'.'user_id' WHERE' articles_users'.'article_id' = 13 AND'users'.'user_id' = 1' – Deekor 2012-07-24 18:22:45