diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index 9ebbcec..4a95799 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -25,7 +25,11 @@ def show end def vote - @article.liked_by current_user + if current_user.voted_for? @article + @article.unliked_by current_user + else + @article.liked_by current_user + end end def create diff --git a/app/views/votes/_btn.html.haml b/app/views/votes/_btn.html.haml index 369a51e..9982591 100644 --- a/app/views/votes/_btn.html.haml +++ b/app/views/votes/_btn.html.haml @@ -1,17 +1,19 @@ -- if user_signed_in? && current_user.voted_for?(votable) - = link_to '#', class: "mr-1" do - %i.far.fa-heart - = votable.votes_for.size -- else - - path = user_signed_in? ? vote_article_path(votable) : '#' - = link_to path, method: :put, remote: true, class: "#{dom_id(votable)}_vote_btn text-muted text-nowrap mr-1" do - %i.far.fa-heart - = votable.votes_for.size +%div{ class: "#{dom_id(votable)}_vote_btn d-flex align-items-end" } + - if user_signed_in? && current_user.voted_for?(votable) + - path = votable.user_id == current_user.id ? '#' : vote_article_path(votable) + = link_to path, method: :put, remote: true, class: "mr-1" do + %i.far.fa-heart + = votable.votes_for.size + - else + - path = user_signed_in? ? vote_article_path(votable) : '#' + = link_to path, method: :put, remote: true, class: "text-muted text-nowrap mr-1" do + %i.far.fa-heart + = votable.votes_for.size -%small.text-muted.ml-1 - %span.font-weight-bold>= link_to votable.user.name, votable.user, class: 'text-dark' - 님 추천 - - if votable.votes_for.size > 1 - · - = votable.votes_for.reject{|vote| vote.voter_id == votable.user_id }.collect {|vote| vote.voter.name }.join(', ') - 님 공감 + %small.text-muted.ml-1 + %span.font-weight-bold>= link_to votable.user.name, votable.user, class: 'text-dark' + 님 추천 + - if votable.votes_for.size > 1 + · + = votable.votes_for.reject{|vote| vote.voter_id == votable.user_id }.collect {|vote| vote.voter.name }.join(', ') + 님 공감