[b][color=red]Objective: To add a new column in pre-built product[/color][/b]
1. create a migration task: add a column for product
[b][color=blue]ruby script/generate migration add_price[/color][/b]
2. edit db/migrate/*****_add_price.rb
3. migrate the new product into database
[b][color=blue]rake db:migrate[/color][/b]
#Please confirm coressponding table in database.
4. rebuild scaffold product
[b][color=blue]ruby script/destroy scaffold product
ruby script/generate scaffold product title:string price:float description:text image_url:string [/color][/b]
#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.
[b][color=blue]ruby script/server[/color][/b]
6. test depot in web browser.
[b][color=blue]http://localhost:3000/products[/color][/b]
1. create a migration task: add a column for product
[b][color=blue]ruby script/generate migration add_price[/color][/b]
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
[b][color=blue]rake db:migrate[/color][/b]
#Please confirm coressponding table in database.
4. rebuild scaffold product
[b][color=blue]ruby script/destroy scaffold product
ruby script/generate scaffold product title:string price:float description:text image_url:string [/color][/b]
#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.
[b][color=blue]ruby script/server[/color][/b]
6. test depot in web browser.
[b][color=blue]http://localhost:3000/products[/color][/b]