Skip to content

Commit

Permalink
Update review display to show up even in HTML without AJAX
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelsey Langlois and LDevinMacKrell committed Dec 7, 2017
1 parent 7e2f6e4 commit 281fa50
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@
.hidelink {
display: none;
}

.reviews {
display: none;
}
1 change: 1 addition & 0 deletions app/views/products/_show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@
<% end %>
<h5><%= link_to "Hide Reviews", products_path, class: "hidelink", 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>
<%= render "reviews/index" %>
</div>
2 changes: 1 addition & 1 deletion app/views/reviews/_index.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div id="reviews-<%= @product.id %>">
<div class="reviews" id="reviews-<%= @product.id %>">
<h2>Reviews</h2>
<% if @product.reviews.any? %>
<div id="reviews">
Expand Down
5 changes: 3 additions & 2 deletions app/views/reviews/index.js.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
$('#show_reviews_<%= @product.id %>').hide().after("<%= j render('reviews/index') %>");
$('#show_reviews_<%= @product.id %>').hide();
$("#reviews-<%= @product.id %>").show();
$('#hide_reviews_<%= @product.id %>').show().click(function(event) {
event.preventDefault();
$('#show_reviews_<%= @product.id %>').show();
$('#hide_reviews_<%= @product.id %>').hide();
$('#reviews-<%= @product.id %>').remove();
$('#reviews-<%= @product.id %>').hide();
});

0 comments on commit 281fa50

Please sign in to comment.