Skip to content

Commit

Permalink
Update app to show and hide reviews on mainpage with book detail.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelsey Langlois and LDevinMacKrell committed Dec 6, 2017
1 parent db1ed79 commit d60d33b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/views/products/_show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@
} %>
</p>
<% end %>
<h5><%= link_to "Hide Reviews", product_reviews_path(@product), id: "hide_reviews_#{@product.id}", remote: true %></h5>
<h5><%= link_to "Hide Reviews", products_path, id: "hide_reviews_#{@product.id}", remote: true %></h5>
<h5><%= link_to "Show Reviews", product_reviews_path(@product), id: "show_reviews_#{@product.id}", remote: true %></h5>
</div>
30 changes: 16 additions & 14 deletions app/views/reviews/_index.html.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<h2>Reviews</h2>
<% if @product.reviews.any? %>
<div id="reviews">
<% @product.reviews.each do |review| %>
<%= render "reviews/review", review: review %>
<% end %>
</div>
<% else %>
<h3>There are no saved reviews for this book!</h3>
<p>Be the first to voyage where no man has gone before!</p>
<% end %>
<% if current_user && current_user.account.has_purchased?(@product) %>
<%= link_to "Add a Review", new_product_review_path(@product), id: "new_link", remote: true %>
<% end %>
<div id="reviews-<%= @product.id %>">
<h2>Reviews</h2>
<% if @product.reviews.any? %>
<div id="reviews">
<% @product.reviews.each do |review| %>
<%= render "reviews/review", review: review %>
<% end %>
</div>
<% else %>
<h3>There are no saved reviews for this book!</h3>
<p>Be the first to voyage where no man has gone before!</p>
<% end %>
<% if current_user && current_user.account.has_purchased?(@product) %>
<%= link_to "Add a Review", new_product_review_path(@product), id: "new_link", remote: true %>
<% end %>
</div>
6 changes: 6 additions & 0 deletions app/views/reviews/index.js.erb
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
$('#show_reviews_<%= @product.id %>').hide().after("<%= j render('reviews/index') %>");
$('#hide_reviews_<%= @product.id %>').show().click(function(event) {
event.preventDefault();
$('#show_reviews_<%= @product.id %>').show();
$('#hide_reviews_<%= @product.id %>').hide();
$('#reviews-<%= @product.id %>').remove();
});

0 comments on commit d60d33b

Please sign in to comment.