'PG:: Deployed to heroku "Error: argument of AND must be type boolean, not type integer"

I am getting a weird error in my app when its been pushed to heroku. The app runs fine one my local machine. I dont know if it's because I am using Mysql locally?

Here is the error I am getting:

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;">

Here the code from my view:

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

What is going wrong here?



Solution 1:[1]

I changed

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

to

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

And it works fine now.

Solution 2:[2]

You should modify the where method like this.

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

not

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

I think this will work.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Deekor
Solution 2 Atsuhiro Teshima