[1]創(chuàng)建應(yīng)用
?? 命令 rails demo
[2]配置數(shù)據(jù)庫配置文件
?? vim config\database.yml,我用的是postgres,文件配置如下:
development:
? adapter: postgresql
? database: zy_rails
? username: postgres
? password: postgres
? host: 127.0.0.1
[3]創(chuàng)建model
? ruby script/generate model userinfos
[4]修改數(shù)據(jù)庫腳本
? vim db\migrate\XXX_create_userinfos.rb
? 內(nèi)容如下:
class CreateUserinfos < ActiveRecord::Migration
? def self.up
??? create_table :userinfos do |t|
?? ?? ?t.column :username,:string,:null => false
?????? ?? ?t.column :upassword,:string,:null => false
??? t.column:email,:string
??? t.column:phone,:string,:limit =>10,:null=> false
??? end
? end
? def self.down
??? drop_table :userinfos
? end
end
[5]創(chuàng)建表
? rake db:migrate
?如果沒有錯誤,ok,查看你的數(shù)據(jù)庫,表已經(jīng)創(chuàng)建。
?
|----------------------------------------------------------------------------------------|
版權(quán)聲明 版權(quán)所有 @zhyiwww
引用請注明來源 http://www.aygfsteel.com/zhyiwww
|----------------------------------------------------------------------------------------|