rails脚手架
来源:互联网 发布:响巢看看软件 编辑:程序博客网 时间:2024/05/17 07:27
rails从2.0的版本开始,将scaffold的模块分离,作为一个项目的插件使用(每建一个项目,如果要使用这个scaffold的功能,就必须为这个项目下载这个插件)。脚手架scaffold可以快速实现基于数据表的相关增改查删的操作。如:我们建立一个网上电子图书的项目depot。
1.先用rails生成这个项目的框架
>rails depot
2.创建数据库
>mysql -u root -p
enter password: ********
mysql>create database depot
mysql>exit
3.创建表,可以使用表的数据定义语言DDL,如create.sql ,假设要创建一个表products,其DDL内容如下:
drop table if exists products;
create table products (
id int not null auto_increment,
title varchar(100) not null,
description text not null,
image_url varchar(200) not null,
price decimal(10,2) not null,
primary key(id)
);
可以用
>mysql -u root -p depot < create.sql 来创建表。
4.使用脚手架scaffold
安装插件
>ruby script/plugin install scaffolding
生成脚手架
>>ruby script/generate scaffold product title:string description:text image_url:string price:decimal
5.运行webrick服务器
ruby script/server
6.查看结果
http://localhost:3000/products
这样,利用rails脚手架,就实现了一个基于表product的简易web管理功能。
附数据配置:
\depot\config>type database.yml
development:
adapter: mysql
database: depot
host: localhost
username: root
password: ******
1.先用rails生成这个项目的框架
>rails depot
2.创建数据库
>mysql -u root -p
enter password: ********
mysql>create database depot
mysql>exit
3.创建表,可以使用表的数据定义语言DDL,如create.sql ,假设要创建一个表products,其DDL内容如下:
drop table if exists products;
create table products (
id int not null auto_increment,
title varchar(100) not null,
description text not null,
image_url varchar(200) not null,
price decimal(10,2) not null,
primary key(id)
);
可以用
>mysql -u root -p depot < create.sql 来创建表。
4.使用脚手架scaffold
安装插件
>ruby script/plugin install scaffolding
生成脚手架
>>ruby script/generate scaffold product title:string description:text image_url:string price:decimal
5.运行webrick服务器
ruby script/server
6.查看结果
http://localhost:3000/products
这样,利用rails脚手架,就实现了一个基于表product的简易web管理功能。
附数据配置:
\depot\config>type database.yml
development:
adapter: mysql
database: depot
host: localhost
username: root
password: ******
test:
adapter: mysql
database: depot
host: localhost
username: root
password:
production:
adapter: mysql
database: depot
host: localhost
username: root
password:
0 0
- rails脚手架
- rails脚手架
- rails脚手架
- 创建Rails脚手架
- rails几款脚手架比拼
- rails脚手架学习入门(一)
- ruby on rails 中脚手架的使用
- 妄想FLEA实现 对 单表/多表 实现类rails 脚手架应用
- ruby脚手架
- Grails 脚手架
- 前端脚手架
- grails脚手架
- Rails
- Rails
- Rails
- rails
- Rails
- rails
- 在创业公司的锻炼心得
- rails命令行命令
- mv命令详解
- Error: Java heap space 堆空间没有足够的RAM用于Java
- 杭州电子科技大学ACM-1096
- rails脚手架
- Android NDK入门2015(环境搭建及第一个小demo)
- Java IO总结(含代码)
- iOS 纯代码适配iPhone6,6+
- 闲扯到底什么是“竞品”
- go中方法的接收者是值或者指针有什么区别吗?
- mysql导入数据load data infile用法
- 一写jquery插件
- 将DATA段放到FRAM中的方法