You should use exists?
if current_user.votes.where(post_id: params[:post_id], value: 1).exists?
If you use only current_user.votes.where(...)
, you get a Relation
object that will always be interpreted as a true
value in the if
, even if tyhe Relation
do not match any line (only false
and nil
are considered as falsy values in Ruby).