Skip to content

Commit

Permalink
추천한 항목을 취소할 수 있습니다
Browse files Browse the repository at this point in the history
  • Loading branch information
mmx900 committed May 1, 2021
1 parent aa17999 commit 6126c92
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
6 changes: 5 additions & 1 deletion app/controllers/articles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 18 additions & 16 deletions app/views/votes/_btn.html.haml
Original file line number Diff line number Diff line change
@@ -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(', ')
님 공감

0 comments on commit 6126c92

Please sign in to comment.