Skip to content

Instantly share code, notes, and snippets.

@shankardevy
Last active July 8, 2017 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shankardevy/46ff53aa23d48c62da957e950ce309ec to your computer and use it in GitHub Desktop.
Save shankardevy/46ff53aa23d48c62da957e950ce309ec to your computer and use it in GitHub Desktop.
<h1>Cart</h1>
<%= if Enum.empty?(@cart.line_items) do %>
<p>Your cart is empty</p>
<% else %>
<%= form_for @cart_changeset, "/cart", fn f -> %>
<table class="table">
<thead>
<tr>
<th>Product name</th>
<th>Pack size</th>
<th>Quantity</th>
<th>Unit price</th>
<th>Subtotal</th>
<td>Remove?</td>
</tr>
</thead>
<tbody>
<%= inputs_for f, :line_items, fn lf -> %>
<tr>
<td><%= lf.data.product_name %></td>
<td><%= lf.data.pack_size %></td>
<td>
<%= hidden_input lf, :product_id %>
<%= number_input lf, :quantity %>
<%= error_tag lf, :quantity %>
</td>
<td>₹ <%= lf.data.unit_price %></td>
<td>₹ <%= lf.data.total %></td>
<td><%= checkbox lf, :delete %></td>
</tr>
<% end %>
<tr>
<td colspan=4>Total</td>
<td>₹ <%= @cart.total %></td>
<td></td>
</tr>
</tbody>
</table>
<div class="form-group">
<%= submit "Update Cart", class: "btn btn-primary" %>
</div>
<% end %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment