zhyiwww
用平实的笔,记录编程路上的点点滴滴………
posts - 536,comments - 394,trackbacks - 0
[1]创建应用
   命令 rails demo
[2]配置数据库配置文件
   vim config\database.yml,我用的是postgres,文件配置如下:
development:
  adapter: postgresql
  database: zy_rails
  username: postgres
  password: postgres
  host: 127.0.0.1
[3]创建model
  ruby script/generate model userinfos
[4]修改数据库脚本
  vim db\migrate\XXX_create_userinfos.rb
  内容如下:
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]创建表
  rake db:migrate
 如果没有错误,ok,查看你的数据库,表已经创建。

 




|----------------------------------------------------------------------------------------|
                           版权声明  版权所有 @zhyiwww
            引用请注明来源 http://www.blogjava.net/zhyiwww   
|----------------------------------------------------------------------------------------|
posted on 2008-12-05 18:09 zhyiwww 阅读(602) 评论(0)  编辑  收藏 所属分类: ruby on rails

只有注册用户登录后才能发表评论。


网站导航: