Last active
August 29, 2015 14:19
-
-
Save tomasero/279d0df797ec0ede9a7e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#cart-panel.cart-panel-hidden | |
#cart-title Cart | |
= inline_svg "shop.svg", class: "cart-svg svg" | |
#cart-info | |
= label :user, :name, 'SID', class: "cart-label" | |
= text_field :user, :name, class: "cart-input" | |
= label :user, :comment, 'Comment', class: "cart-label" | |
.comment-arrow | |
= text_area :user, :comment, class: "cart-textarea", cols: "18", rows: "2" | |
= label :user, :items, 'Items', class: "cart-label" | |
#cart-items | |
- @cart.each_with_index do |item, index| | |
.cart-item | |
= text_field "item#{index}", :quantity, value: item[:quantity], class: "cart-item-quantity" | |
= label "item#{index}", :name, item[:name], class: "cart-item-name" | |
#checkout-footer | |
=link_to "Checkout", checkout_path(hash: session[:cart]), method: :post, id: "checkout-button" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ItemsController < ApplicationController | |
def checkout | |
cart = params[:hash] | |
redirect_to transactions_path(cart: cart) | |
end | |
def add_item | |
@cart = session[:cart] | |
@id = params[:id] | |
if @cart.has_key? @id | |
@cart[@id] += 1 | |
else | |
@cart[@id] = 1 | |
end | |
session[:cart] = @cart | |
redirect_to items_path | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%table#inventory-table | |
%thead | |
%tr | |
%th{:class => ('hilite' if @sort == 'name'), :id => 'title_header'}= link_to "Item", items_path(:sort => 'name') | |
%th{:class => ('hilite' if @sort == 'quantity'), :id => 'title_header'}= link_to "Quantity", items_path(:sort => 'quantity') | |
%th{:class => ('hilite' if @sort == 'price'), :id => 'title_header'}= link_to "Price", items_path(:sort => 'price') | |
%th{:class => ('hilite' if @sort == 'kind'), :id => 'title_header'}= link_to "Kind", items_path(:sort => 'kind') | |
%th{:class => ('hilite' if @sort == 'status'), :id => 'title_header'}= link_to "Status", items_path(:sort => 'status') | |
%th.add-column Add | |
%tbody | |
- @items.each do |item| | |
%tr | |
%td= link_to item.name, item_path(item) | |
%td= item.quantity | |
%td= item.price | |
%td= item.kind | |
%td= item.status | |
%td.add-column | |
=link_to add_item_path(:id => item.id), method: :post do | |
= inline_svg "plus.svg", class: "add-svg" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The problem is making a transaction given a list of items. I want to figure out how to contain every object I add to the cart in an array. This would enable me to easy extract the params in the controller, without creating and keeping an array of items in my controller.
e.g.
items = [
{name: “item1”, …},
{name: “item2”, …}
]