Created
February 16, 2010 23:06
-
-
Save trek/306056 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
class CreateShirts < ActiveRecord::Migration | |
def self.up | |
create_table :shirts do |t| | |
t.string :size | |
t.string :color | |
t.string :style | |
t.belongs_to :design | |
t.belongs_to :order | |
t.timestamps | |
end | |
end | |
def self.down | |
drop_table :shirts | |
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
class CreateOrders < ActiveRecord::Migration | |
def self.up | |
create_table :orders do |t| | |
t.datetime :paid | |
t.datetime :shipped | |
t.belongs_to :customer | |
t.timestamps | |
end | |
end | |
def self.down | |
drop_table :orders | |
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
class CreateCustomers < ActiveRecord::Migration | |
def self.up | |
create_table :customers do |t| | |
t.string :first_name | |
t.string :last_name | |
t.boolean :artist | |
t.timestamps | |
end | |
end | |
def self.down | |
drop_table :customers | |
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
class CreateDesigns < ActiveRecord::Migration | |
def self.up | |
create_table :designs do |t| | |
t.string :image | |
t.belongs_to :customer | |
t.timestamps | |
end | |
end | |
def self.down | |
drop_table :designs | |
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
class Customer < ActiveRecord::Base | |
Customer.has_many(:designs) # as a designer | |
Customer.has_many(:orders) | |
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
class Design < ActiveRecord::Base | |
Design.has_many(:shirts) | |
Design.belongs_to(:customer) # the person who designed it | |
Design.has_many(:orders, {:through => :shirts}) | |
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
class DesignsController < ApplicationController | |
def index | |
end | |
def show | |
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
class ItemsController < ApplicationController | |
def new | |
end | |
def create | |
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
class Order < ActiveRecord::Base | |
Order.belongs_to(:customer) | |
Order.has_many(:items) | |
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
class OrdersController < ApplicationController | |
def new | |
end | |
def new | |
end | |
def create | |
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
ActionController::Routing::Routes.draw do |map| | |
map.site_root('/', { | |
:controller => 'designs', | |
:action => 'index', | |
:conditions => {:method => :get} | |
}) | |
map.design('/designs/:permalink', { | |
:controller => 'designs', | |
:action => 'show', | |
:conditions => {:method => :get} | |
}) | |
map.new_item('/buy/:design_permalink', { | |
:controller => 'items', | |
:action => 'new', | |
:conditions => {:method => :get} | |
}) | |
map.add_item_to_cart('/items', { | |
:controller => 'items', | |
:action => 'create', | |
:conditions => {:method => :post} | |
}) | |
map.shopping_cart('/checkout', { | |
:controller => 'orders', | |
:action => 'new', | |
:conditions => {:method => :get} | |
}) | |
map.finalize_order('/orders', { | |
:controller => 'orders', | |
:action => 'create', | |
:conditions => {:method => :post} | |
}) | |
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
class Shirt < ActiveRecord::Base | |
Shirt.belongs_to(:design) | |
Shirt.belongs_to(:order) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment