Welcome 微信登录

首页 / 软件开发 / JAVA / Ruby on rails开发从头来(windows)(十一)-订单(Order)

Ruby on rails开发从头来(windows)(十一)-订单(Order)2011-12-02 博客园 Cure在上次的内容里,我们实现了清空购物车和金额的格式化处理。这次实现订单的模块。

1.首先,我们要在数据库里创建Order表,创建表的Sql如下:

create table orders (id int not null auto_increment,name varchar(100) not null,email varchar(255) not null,address text not null,pay_type char(10) not null,primary key (id));
我们还要重新创建line_item表,下面是Sql:

create table line_items (id int not null auto_increment,product_id int not null,order_id int not null,quantity int not null default 0,unit_price decimal(10,2) not null,constraint fk_items_product foreign key (product_id) references products(id),constraint fk_items_order foreign key (order_id) references orders(id),primary key (id));
在InstantRail里,可以使用phpMyAdmin来执行Sql。

运行命令行,生成Order的Model,如图: