How do you know if the user Rails voted?



  • Hello, there is such a 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
    

    At first, I'm checking or entering the user, and then if he voted and put the answer, hiding the button like and displaying the dislike button, or vice versa, hiding the button dislike and displaying the button for like. But for reasons I don't understand, only a dislike button is always displayed. So when you try to dislike, nothing happens... If the conditions are to be cleaned up and just two buttons left, it's all right.



  • I decided to replace the stork.

    - if current_user.voted_for? answer and answer.liked_by current_user
    

    - if current_user.voted_up_on? answer
    

Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2