- 利用ruby on rails 的效率,快速建立一个简单的项目
一、新建项目,指定数据库,配置数据库的驱动
jruby -S rails new project_name -d postgresql
解释一下命令:
project_name 项目的名称
-d postgresql 指定数据库
配置config下database.yml的配置
development:
adapter: postgresql
encoding: unicode
host: 192.168.0.107 ---数据库所在位置
database: beijing_xuanwu_app ---数据库名称
username: postgres
password: postgres
二 、生成字段
利用rails里面的生成器,脚手架生成对应的model,view, controller等
jruby -S rails generate scaffold patient_info patient_uuid:string name:string age:integer sex:string birthday:string address:string phone1:string phone2:string patient_type:string
三、生成数据库中对应的表
利用迁移命令
jruby -S rake db:migrate
四 、增加字段
生成迁移文件,add_columns_to_patient_info —迁移文件的名称
bb:string —-bb 字段名, string 类型
jruby -S rails generate migration add_columns_to_patient_info bb:string
最后不要忘记 执行 三 的迁移命令,操作数据库中的表