From 62852285b74a02e3ff65d2f8cee66c551911649a Mon Sep 17 00:00:00 2001 From: Nils Dittberner Date: Wed, 16 Nov 2016 15:11:00 +0100 Subject: [PATCH] Iteration F4. --- app/controllers/carts_controller.rb | 2 +- app/helpers/application_helper.rb | 6 ++++++ app/views/layouts/application.html.erb | 6 +++--- app/views/line_items/create.js.erb | 2 ++ 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/controllers/carts_controller.rb b/app/controllers/carts_controller.rb index 36a3270..db68290 100644 --- a/app/controllers/carts_controller.rb +++ b/app/controllers/carts_controller.rb @@ -59,7 +59,7 @@ class CartsController < ApplicationController @cart.destroy if @cart.id == session[:cart_id] session[:cart_id] = nil respond_to do |format| - format.html { redirect_to store_index_url, notice: 'Your cart is currently empty.' } + format.html { redirect_to store_index_url } format.json { head :no_content } end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..fcdebb4 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,8 @@ module ApplicationHelper + def hidden_div_if(condition, attributes = {}, &block) + if condition + attributes["style"] = "display: none" + end + content_tag("div", attributes, &block) + end end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index efdb61c..cf005e7 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -15,11 +15,11 @@
-
- <% if @cart %> + <% if @cart %> + <%= hidden_div_if(@cart.line_items.empty?, id: 'cart') do %> <%= render @cart %> <% end %> -
+ <% end %>
  • Home
  • diff --git a/app/views/line_items/create.js.erb b/app/views/line_items/create.js.erb index 96a5666..47d7f7e 100644 --- a/app/views/line_items/create.js.erb +++ b/app/views/line_items/create.js.erb @@ -1,3 +1,5 @@ +if ($('#cart tr').length == 1) { $('#cart').show('blind', 1000); } + $('#cart').html("<%=j render(@cart) %>") $('#current_item').css({'background-color':'#88ff88'})