Answer the question
In order to leave comments, you need to log in
How to find out if a Rails user voted (acts_votable gem)?
Hello, I have the following condition:
- if user_signed_in?
- if current_user.voted_for? answer and answer.liked_by current_user
= link_to unlike_answer_path(answer), class: "unlike", remote: true, method: :put do
button.btn.btn-info aria-label=("Left Align") type="button"
span.glyphicon.glyphicon-thumbs-down.glyphicon-align-center aria-hidden="true"
span.badge id="badge_downvote_value" = answer.get_downvotes.size
- elsif current_user.voted_for? answer and answer.disliked_by current_user
= link_to like_answer_path(answer), class: "like", remote: true, method: :put do
button.btn.btn-info aria-label=("Left Align") type="button"
span.glyphicon.glyphicon-thumbs-up.glyphicon-align-center aria-hidden="true"
span.badge id="badge_upvote_value" = answer.get_upvotes.size
Answer the question
In order to leave comments, you need to log in
In the second line
- if current_user.voted_for? answer and answer.liked_by current_user
you do the same thing - check if the user has voted. Do it
like this
- if current_user.voted_up_on? @answer
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question