论坛首页 编程语言技术论坛

Depot Sample in Rails 2.0, Step 2

浏览 2092 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-06-24  
Objective: To add a new column in pre-built product

1. create a migration task: add a column for product
ruby script/generate migration add_price

2. edit db/migrate/*****_add_price.rb
class AddPrice < ActiveRecord::Migration
	  def self.up
	    add_column  :products,  :price, :decimal, :precision => 8,  :scale => 2, :default => 0
	  end

	  def self.down
	    remove_column :products,  :price
	  end
	end


3. migrate the new product into database
rake db:migrate
#Please confirm coressponding table in database.

4. rebuild scaffold product
ruby script/destroy scaffold product
ruby script/generate scaffold product title:string price:float description:text image_url:string

#the scaffold product should be automatically rebuilt, but actually it did not on my machine. If someone can help me out, appreciate.

5. start Webrick server.
ruby script/server

6. test depot in web browser.
http://localhost:3000/products

论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics