create the model and table

 work>ruby script/generate model product

the generator creates a bunch of files. The two we're interested in are the model itself product.rb, and the migration 001_create_products.rb.

In this file, there were two ruby methods.

class CretaeProducts < ActiveRecord::Migration

def self.up

  create_table :products do |t|

    t.column :title,  :string

    t.column :description, :text

  end

def self.down

  drop_table :products

end

end

get rails to apply the migration to the database.

work> rake db:migrate

if you want to roll back ,you could use

work> rake db:migrate VERSION=0

and the products table will gone.

call the rake db:migrate will re-create it.

阅读更多
个人分类: rails
想对作者说点什么? 我来说一句

学生综合素质评价数据库

2014年04月30日 8KB 下载

没有更多推荐了,返回首页

不良信息举报

create the model and table

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭