Skip to content

Instantly share code, notes, and snippets.

@rocodev-tech
Last active August 29, 2015 14:02
Show Gist options
  • Save rocodev-tech/5799788d0553db155a4a to your computer and use it in GitHub Desktop.
Save rocodev-tech/5799788d0553db155a4a to your computer and use it in GitHub Desktop.
app/views/carts/index.html.erb
<div class="row">
<div class="col-md-12">
<h2> 購物車 </h2>
<table class="table table-bordered">
<thead>
<tr>
<th>商品資訊</th>
<th></th>
<th>單價</th>
</tr>
</thead>
<tbody>
<% current_cart.items.each do |product| %>
<tr>
<td><%= render_product_photo(product.default_photo) %></td>
<td>
<%= link_to(product.title, admin_product_path(product)) %>
</td>
<td> <%= product.price %> </td>
</tr>
<% end %>
</tbody>
</table>
<div class="total group">
<span class="pull-right">
<span> 總計 <%= render_cart_total_price(current_cart) %> NTD
</span>
</div>
<hr>
<div class="checkout">
<%= link_to("確認結賬", "#" , :method => :post , :class => "btn btn-primary btn-lg btn-danger pull-right") %>
</div>
</div>
</div>
@wildjcrt
Copy link

rails-4 講義 p38,要補上以下動作

config/routes 加上 checkout

resources :carts do
  collection do
    post 'checkout'
  end
end

現在看到這個 index.html.erb 檔案,39 行,要改成:

<%= link_to("確認結賬", checkout_carts_path , :method => :post , :class => "btn btn-primary btn-lg btn-danger pull-right") %>

@wildjcrt
Copy link

app/models/user.rb 加入:

has_many :orders

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment