9.3 Iteration D3: Highlighting Changes 9.1 Iteration D1: Moving the Cart
edit app/views/store/index.html.erb
<%= form_tag({:action=>'add_to_cart', :id=>product}, :remote=>true) do %>
<%= submit_tag "Add to Cart" %>
<% end %>
edit app/views/layouts/store.html.erb
<html>
<head>
<title>Pragprog Books Online Store</title>
<%= stylesheet_link_tag "depot", :media => "all" %>
<%= javascript_include_tag :defaults %>
</head>
edit app/controllers/store_controller.rb
def add_to_cart
product = Product.find(params[:id])
@cart = find_cart
@cart.add_product(product)
respond_to do |format|
format.js
end
rescue ActiveRecord::RecordNotFound
logger.error("Attempt to access invalid product #{params[:id]}")
redirect_to_index("Invalid product")
end
edit app/views/store/add_to_cart.js.rjs
page.replace_html("cart", :partial => "cart", :object => @cart)
9.3 Iteration D3: Highlighting Changes 9.1 Iteration D1: Moving the Cart