Skip to content

Commit

Permalink
9.2 イテレーションD2 Ajax based Cart
Browse files Browse the repository at this point in the history
RJS を利用して Ajax 通信のカートを実装した
  • Loading branch information
kyanny committed Jan 21, 2010
1 parent be42c93 commit 3d81f52
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion depot/app/controllers/store_controller.rb
Expand Up @@ -14,7 +14,9 @@ def add_to_cart
@cart = find_cart
@cart.add_product(product)
session[:counter] = 0
redirect_to_index
respond_to do |format|
format.js
end
rescue
logger.error("無効な商品#{params[:id]}にアクセスしようとしました")
redirect_to_index("無効な商品です")
Expand Down
1 change: 1 addition & 0 deletions depot/app/views/layouts/store.html.erb
Expand Up @@ -6,6 +6,7 @@
<!-- START:stylesheet -->
<%= stylesheet_link_tag "depot", :media => "all" %><!-- <label id="code.slt"/> -->
<!-- END:stylesheet -->
<%= javascript_include_tag :defaults %>
</head>
<body id="store">
<div id="banner">
Expand Down
1 change: 1 addition & 0 deletions depot/app/views/store/add_to_cart.js.rjs
@@ -0,0 +1 @@
page.replace_html("cart", :partial => "cart", :object => @cart)
4 changes: 3 additions & 1 deletion depot/app/views/store/index.html.erb
Expand Up @@ -7,7 +7,9 @@
<%= product.description %>
<div class="price-line">
<span class="price"><%= number_to_currency(product.price) %></span>
<%= button_to "カートに入れる", :action => "add_to_cart", :id => product %>
<% form_remote_tag :url => { :action => "add_to_cart", :id => product } do %>
<%= submit_tag "カートに入れる" %>
<% end %>
</div>
</div>
<% end %>

0 comments on commit 3d81f52

Please sign in to comment.