diff --git a/app/controllers/line_items_controller.rb b/app/controllers/line_items_controller.rb index 8bea84d..b636c96 100644 --- a/app/controllers/line_items_controller.rb +++ b/app/controllers/line_items_controller.rb @@ -34,6 +34,7 @@ class LineItemsController < ApplicationController respond_to do |format| if @line_item.save format.html { redirect_to @line_item.cart } + format.js format.json { render :show, status: :created, location: @line_item } else format.html { render :new } diff --git a/app/views/line_items/create.js.erb b/app/views/line_items/create.js.erb new file mode 100644 index 0000000..24cfafe --- /dev/null +++ b/app/views/line_items/create.js.erb @@ -0,0 +1 @@ +$('#cart').html("<%=j render(@cart) %>") diff --git a/app/views/store/index.html.erb b/app/views/store/index.html.erb index 300f70d..4ba2474 100644 --- a/app/views/store/index.html.erb +++ b/app/views/store/index.html.erb @@ -11,7 +11,7 @@ <%= sanitize(product.description) %>
<%= number_to_currency(product.price) %> - <%= button_to 'Add To Cart', line_items_path(product_id: product) %> + <%= button_to 'Add To Cart', line_items_path(product_id: product), remote: true %>
<% end %>