Skip to content

Commit

Permalink
atom
Browse files Browse the repository at this point in the history
  • Loading branch information
haio committed Oct 11, 2012
1 parent ee480a6 commit 4ff116c
Show file tree
Hide file tree
Showing 20 changed files with 91 additions and 17 deletions.
33 changes: 33 additions & 0 deletions app/assets/stylesheets/depot.css
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,36 @@
border-bottom: 1px dotted #595;
margin-bottom: 10px;
}

/* Styles for order form */
.depot_form fieldset {
background: #efe;
}

.depot_form legend {
color: #dfd;
background: #141;
font-family: sans-serif;
padding: 0.2em 1em;
}

.depot_form label {
width: 5em;
float: left;
text-align: right;
padding-top: 0.2em;
margin-right: 0.1em;
display: block;
}

.depot_form select, .depot_form textarea, .depot_form input {
margin-left: 0.5em;
}

.depot_form .submit {
margin-left: 4em;
}

.depot_form div {
margin: 0.5em 0;
}
33 changes: 23 additions & 10 deletions app/assets/stylesheets/scaffolds.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,47 @@ body {
color: #333;
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px; }
line-height: 18px;
}

p, ol, ul, td {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px; }
line-height: 18px;
}

pre {
background-color: #eee;
padding: 10px;
font-size: 11px; }
font-size: 11px;
}

a {
color: #000;
&:visited {
color: #666; }
color: #666;
}
&:hover {
color: #fff;
background-color: #000; } }
background-color: #000;
}
}

div {
&.field, &.actions {
margin-bottom: 10px; } }
margin-bottom: 10px;
}
}

#notice {
color: green; }
color: green;
}

.field_with_errors {
padding: 2px;
background-color: red;
display: table; }
display: table;
}

#error_explanation {
width: 450px;
Expand All @@ -50,7 +60,10 @@ div {
margin: -7px;
margin-bottom: 0px;
background-color: #c00;
color: #fff; }
color: #fff;
}
ul li {
font-size: 12px;
list-style: square; } }
list-style: square;
}
}
8 changes: 8 additions & 0 deletions app/controllers/products_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,12 @@ def destroy
format.json { head :no_content }
end
end

def who_bought
@product = Product.find(params[:id])
respond_to do |format|
format.atom
format.xml {render :xml => @product }
end
end
end
1 change: 1 addition & 0 deletions app/models/line_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class LineItem < ActiveRecord::Base
attr_accessible :cart_id, :product_id
belongs_to :product
belongs_to :cart
belongs_to :order

def total_price
product.price * quantity
Expand Down
1 change: 1 addition & 0 deletions app/models/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class Product < ActiveRecord::Base

default_scope :order => 'title'
has_many :line_items
has_many :orders, :through => :line_items
before_destroy :ensure_not_referrenced_by_any_line_item

validates :title, :description, :image_url, :presence => true
Expand Down
1 change: 1 addition & 0 deletions app/views/carts/_cart.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
</table>
<!-- END_HIGHLIGHT -->

<%= button_to "Checkout", new_order_path, :method => :get %>
<%= button_to 'Empty cart', cart, method: :delete,
data: { confirm: 'Are you sure?' } %>

2 changes: 2 additions & 0 deletions app/views/line_items/create.js.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//#START_HIGHLIGHT
$("#notice").hide();

if ($('#cart tr').length == 1) { $('#cart').show('blind', 1000); }

$('#cart').html("<%=j render @cart %>");
Expand Down
6 changes: 5 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
Depot::Application.routes.draw do
resources :orders

resources :line_items

resources :carts

get "store/index"

resources :products
resources :products do
get :who_bought, :on => :member
end

# The priority is based upon order of creation:
# first created -> highest priority.
Expand Down
Binary file modified db/development.sqlite3
Binary file not shown.
12 changes: 11 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20120920124326) do
ActiveRecord::Schema.define(:version => 20121011144720) do

create_table "carts", :force => true do |t|
t.datetime "created_at", :null => false
Expand All @@ -24,6 +24,16 @@
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "quantity", :default => 1
t.integer "order_id"
end

create_table "orders", :force => true do |t|
t.string "name"
t.string "address"
t.string "email"
t.string "pay_type"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end

create_table "products", :force => true do |t|
Expand Down
10 changes: 6 additions & 4 deletions test/fixtures/line_items.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html

one:
product_id: 1
cart_id: 1
product: ruby
#START_HIGHLIGHT
order: one
#END_HIGHLIGHT

two:
product_id: 1
cart_id: 1
product: ruby
cart: one
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 0 additions & 1 deletion tmp/pids/server.pid

This file was deleted.

0 comments on commit 4ff116c

Please sign in to comment.