Skip to content

Commit

Permalink
9章 Ajax 9.1 イテレーションD1
Browse files Browse the repository at this point in the history
カートをサイドバーに移動した
部分テンプレートを使ってカート部分だけをレンダリングさせた
  • Loading branch information
kyanny committed Jan 21, 2010
1 parent bea067f commit c6fd561
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 7 deletions.
1 change: 1 addition & 0 deletions depot/app/controllers/store_controller.rb
Expand Up @@ -6,6 +6,7 @@ def index
session[:counter] = 0
end
session[:counter] += 1
@cart = find_cart
end

def add_to_cart
Expand Down
4 changes: 4 additions & 0 deletions depot/app/views/layouts/store.html.erb
Expand Up @@ -14,6 +14,10 @@
</div>
<div id="columns">
<div id="side">
<div id="cart">
<%= render(:partial => "cart", :object => @cart) %>
</div>

<a href="http://www....">Home</a><br />
<a href="http://www..../faq">Questions</a><br />
<a href="http://www..../news">News</a><br />
Expand Down
12 changes: 12 additions & 0 deletions depot/app/views/store/_cart.html.erb
@@ -0,0 +1,12 @@
<div class="cart-title">Your Cart</div>
<table>
<%= render(:partial => "cart_item", :collection => cart.items) %>

<tr class="total-line">
<td colspan="2">Total</td>
<td class="total-cell"><%= number_to_currency(cart.total_price) %></td>
</tr>

</table>

<%= button_to "Empty cart", :action => :empty_cart %>
5 changes: 5 additions & 0 deletions depot/app/views/store/_cart_item.html.erb
@@ -0,0 +1,5 @@
<tr>
<td><%= cart_item.quantity %>&times;</td>
<td><%=h cart_item.title %></td>
<td class="item-price"><%= number_to_currency(cart_item.price) %></td>
</tr>
8 changes: 1 addition & 7 deletions depot/app/views/store/add_to_cart.html.erb
@@ -1,12 +1,6 @@
<div class="cart-title">Your Cart</div>
<table>
<% for item in @cart.items %>
<tr>
<td><%= item.quantity %>&times;</td>
<td><%=h item.title %></td>
<td class="item-price"><%= number_to_currency(item.price) %></td>
</tr>
<% end %>
<%= render(:partial => "cart_item", :collection => @cart.items) %>

<tr class="total-line">
<td colspan="2">Total</td>
Expand Down
15 changes: 15 additions & 0 deletions depot/public/stylesheets/depot.css
Expand Up @@ -175,6 +175,21 @@ h1 {
}
/* END:cartmain */

/* START:cartside */
/* Styles for the cart in the sidebar */

#cart, #cart table {
font-size: smaller;
color: white;
}

#cart table {
border-top: 1px dotted #595;
border-bottom: 1px dotted #595;
margin-bottom: 10px;
}
/* END:cartside */

/* The error box */

.fieldWithErrors {
Expand Down

0 comments on commit c6fd561

Please sign in to comment.