ruby on rails(10) 处理订单
订单处置,首先要有一个订单的详细列表(包括数量,价钱啥的)和一个对于个人的一些信息的一个表。因而我们创造两个模型,line_item(列表项),order(列表),其后编者如次
/db/migrate xxx_create_order xxx_line_item
Ruby代码
一.class CreateOrders < ActiveRecord::Migration
二.def self.up
3. create_table :orders do |t|
4. t.string :name
5. t.text :address
6. t.string :email
7. t.string :pay_type, :limit => 十
8. t.timestamps
9. end
十.end
11.
12.def self.down
13. drop_table :orders
14.end
15.d
class CreateOrders < ActiveRecord::Migration
def self.up
create_table :orders do |t|
t.string :name
t.text :address
t.string :email
t.string :pay_type, :limit => 十
t.timestamps
end
end
def self.down
drop_table :orders
end
end
Ruby代码
1. class CreateLineItems < ActiveRecord::Migration
二.def self.up
3. create_table :line_items do |t|
4. t.integer :product_id, :null => false,:options =>
5. "CONSTRAINT fk_line_items_products REFERENCES products(id)"
6. t.integer :order_id,:null => false, :options =>
7. "CONSTRAINT fk_line_items_orders ReEFERENCES orders(id)"
8. t.integer :quantity, :null => false
9. t.decimal :total_price, :null => false,:precision => 八,:scale => 二
10. t.timestamps
11. end
12.end
13.
14.def self.down
15. drop_table :line_items
16.end
17.d
class CreateLineItems < ActiveRecord::Migration
def self.up
create_table :line_items do |t|
t.integer :product_id, :null => false,:options =>
"CONSTRAINT fk_line_items_products REFERENCES products(id)"
t.integer :order_id,:null => false, :options =>
"CONSTRAINT fk_line_items_orders ReEFERENCES orders(id)"
t.integer :quantity, :null => false
t.decimal :total_price, :null => false,:precision => 八,:scale => 二
t.timestamps
end
end
def self.down
drop_table :line_items
end
end
t.integer :product_id, :null => false,:options =>
"CONSTRAINT fk_line_items_products REFERENCES p
相关文档:
两种不同的语言,不同的表达!
Python脚本实现.
""
"
File Name : clean.py
File Date : 2009/11/5 14:22:56
Author : DannyLai
Purpose : Cle ......
一 安装ruby
$sudo apt-get install ruby irb rdoc
二 安装gem
1.到这里下载 ,最好是最新版本,我的1.3.5
解压,切换到当前目录,执行$sudo ruby setup.rb
或者这样:
$ tar xzvf rubygems-1.3.5.tgz (解压)
$ cd rubygems-1.3.5 (切换到此目录)
$ sudo ruby setup ......
最近在看John E.Hopcroft,Rajeev Motwani,Jeffrey D.Ullman 三巨头写的Introduction to Automata Theory,Language,and Computation,想写一个Turing 机验证一下自己写的状态转移函数对不对。懒得很,网上搜了几个不错的。但Ruby Quiz 上的这个最简单。
162 Turing 机
问题描述
Quiz
description by James Edward Gray ......
client.rb
======================================================================
require 'drb'
SERVER_IP = 'druby://127.0.0.1:6666'
CLIENT_IP = 'druby://10.10.10.102:7777'
c_path = 'd:/test/'
class Client
def initialize(path)
Dir.chdir(path)
end
def mk ......