This repository has been archived by the owner on May 25, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
45 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,24 @@ | ||
class UpvotesController < ApplicationController | ||
def create | ||
# Upvote? | ||
product = Product.find(params[:product_id]) | ||
product.upvotes.create! user: current_user | ||
redirect_to products_path | ||
@product = Product.find(params[:product_id]) | ||
@product.upvotes.create! user: current_user | ||
|
||
respond_to do |format| | ||
format.html { redirect_to products_path } | ||
format.js | ||
end | ||
end | ||
|
||
def destroy | ||
upvote = Upvote.find(params[:id]) | ||
@product = upvote.product | ||
|
||
upvote.destroy | ||
redirect_to products_path | ||
|
||
respond_to do |format| | ||
format.html { redirect_to products_path } | ||
format.js | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<% if user_signed_in? %> | ||
<% if current_user.voted_for?(product) %> | ||
<%= link_to upvote_path(current_user.upvotes.where(product: product).first), remote: true, method: :delete, class: 'product-upvote product-upvoted' do %> | ||
<div class="product-arrow"></div> | ||
<div class='product-count'> | ||
<%= product.upvotes.size %> | ||
</div> | ||
<% end %> | ||
<% else %> | ||
<%= link_to upvotes_path(product_id: product.id), remote: true, method: :post, class: 'product-upvote' do %> | ||
<div class="product-arrow"></div> | ||
<div class='product-count'> | ||
<%= product.upvotes.size %> | ||
</div> | ||
<% end %> | ||
<% end %> | ||
<% else %> | ||
<div class='product-upvote'> | ||
<div class="product-arrow"></div> | ||
<div class='product-count'> | ||
<%= product.upvotes.size %> | ||
</div> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
$('#product-<%= @product.id %>').html('<%= j render 'upvotes/show', product: @product %>'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
$('#product-<%= @product.id %>').html('<%= j render 'upvotes/show', product: @product %>'); |