Depot Sample in Rails 2.0, Step 2

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

你可能感兴趣的:(Web,Ruby,UP,Rails,ActiveRecord)