The Depot Application

The Depot Application

6.3 Iteration A2: Add a Missing Column 6.2 Creating the Products Model and Maintenance Application

6.3 Iteration A2: Add a Missing Column

rails generate migration add_price_to_product price:decimal
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:14: warning: already initialized constant VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:14: warning: already initialized constant RubyGemsVersion
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:194: warning: already initialized constant MUTEX
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:196: warning: already initialized constant RubyGemsPackageVersion
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:202: warning: already initialized constant WIN_PATTERNS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:1079: warning: already initialized constant MARSHAL_SPEC_DIR
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:1084: warning: already initialized constant YAML_SPEC_DIR
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/version.rb:72: warning: already initialized constant VERSION_PATTERN
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/requirement.rb:20: warning: already initialized constant OPS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/requirement.rb:30: warning: already initialized constant OP_RE
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/version.rb:246: warning: already initialized constant Requirement
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:18: warning: already initialized constant TYPES
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/platform.rb:171: warning: already initialized constant RUBY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/platform.rb:177: warning: already initialized constant CURRENT
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:39: warning: already initialized constant NONEXISTENT_SPECIFICATION_VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:50: warning: already initialized constant CURRENT_SPECIFICATION_VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:56: warning: already initialized constant SPECIFICATION_VERSION_HISTORY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:72: warning: already initialized constant MARSHAL_FIELDS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:75: warning: already initialized constant TODAY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/source_index.rb:593: warning: already initialized constant Cache
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:14: warning: already initialized constant DEFAULT_BACKTRACE
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:15: warning: already initialized constant DEFAULT_BENCHMARK
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:16: warning: already initialized constant DEFAULT_BULK_THRESHOLD
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:17: warning: already initialized constant DEFAULT_VERBOSITY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:18: warning: already initialized constant DEFAULT_UPDATE_SOURCES
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:24: warning: already initialized constant OPERATING_SYSTEM_DEFAULTS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:30: warning: already initialized constant PLATFORM_DEFAULTS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:53: warning: already initialized constant SYSTEM_WIDE_CONFIG_FILE
      invoke  active_record
      create    db/migrate/20100211191137_add_price_to_product.rb
cat db/migrate/20100211191137_add_price_to_product.rb
class AddPriceToProduct < ActiveRecord::Migration
  def self.up
    add_column :products, :price, :decimal
  end
 
  def self.down
    remove_column :products, :price
  end
end
edit db/migrate/20100211191137_add_price_to_product.rb
class AddPriceToProduct < 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
rake db:migrate
mv 20100211191137_add_price_to_product.rb 20100301000002_add_price_to_product.rb
(in /home/rubys/git/awdwr/work-191/depot)
==  AddPriceToProduct: migrating ==============================================
-- add_column(:products, :price, :decimal, {:precision=>8, :scale=>2, :default=>0})
   -> 0.0098s
==  AddPriceToProduct: migrated (0.0098s) =====================================
 
sqlite3 db/development.sqlite3 .schema
CREATE TABLE "products" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255), "description" text, "image_url" varchar(255), "created_at" datetime, "updated_at" datetime, "price" decimal(8,2) DEFAULT 0);
CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL);
CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version");
edit app/views/products/index.html.erb
<h1>Listing products</h1>
 
<table>
  <tr>
    <th>Title</th>
    <th>Description</th>
    <th>Image url</th>
    <th>Price</th>
    <th></th>
    <th></th>
    <th></th>
  </tr>
 
<% @products.each do |product| %>
  <tr>
    <td><%= product.title %></td>
    <td><%= product.description %></td>
    <td><%= product.image_url %></td>
    <td><%= product.price %></td>
    <td><%= link_to 'Show', product %></td>
    <td><%= link_to 'Edit', edit_product_path(product) %></td>
    <td><%= link_to 'Destroy', product, :confirm => 'Are you sure?',
                                        :method => :delete %></td>
  </tr>
<% end %>
</table>
 
<br />
 
<%= link_to 'New product', new_product_path %>
edit app/views/products/_form.html.erb
<% form_for(@product) do |f| %>
  <%= f.error_messages %>
 
  <div class="field">
    <%= f.label :title %><br />
    <%= f.text_field :title %>
  </div>
  <div class="field">
    <%= f.label :description %><br />
    <%= f.text_area :description, :rows => 6 %>
  </div>
  <div class="field">
    <%= f.label :image_url %><br />
    <%= f.text_field :image_url %>
  </div>
  <div class="field">
    <%= f.label :price %><br />
    <%= f.text_field :price %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>
edit app/views/products/show.html.erb
<p>
  <b>Title:</b>
  <%= @product.title %>
</p>
 
<p>
  <b>Description:</b>
  <%= @product.description %>
</p>
 
<p>
  <b>Image url:</b>
  <%= @product.image_url %>
</p>
 
<p>
  <b>Price:</b>
  <%= @product.price %>
</p>
 
<%= link_to 'Edit', edit_product_path(@product) %> |
<%= link_to 'Back', products_path %>
get /products

Listing products

Title Description Image url Price
Pragmatic Version Control <p> This book is a recipe-based approach to using Subversion that will get you up and running quickly---and correctly. All projects need version control: it's a foundational piece of any project's infrastructure. Yet half of all project teams in the U.S. dont use any version control at all. Many others dont use it well, and end up experiencing time-consuming problems. </p> /images/svn.jpg 0.0 Show Edit Destroy

New product
get /products/1

Title: Pragmatic Version Control

Description: <p> This book is a recipe-based approach to using Subversion that will get you up and running quickly---and correctly. All projects need version control: it's a foundational piece of any project's infrastructure. Yet half of all project teams in the U.S. dont use any version control at all. Many others dont use it well, and end up experiencing time-consuming problems. </p>

Image url: /images/svn.jpg

Price: 0.0

Edit | Back
get /products/new

New product





Back
rake test
(in /home/rubys/git/awdwr/work-191/depot)
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:14: warning: already initialized constant VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:14: warning: already initialized constant RubyGemsVersion
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:194: warning: already initialized constant MUTEX
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:196: warning: already initialized constant RubyGemsPackageVersion
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:202: warning: already initialized constant WIN_PATTERNS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:1079: warning: already initialized constant MARSHAL_SPEC_DIR
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:1084: warning: already initialized constant YAML_SPEC_DIR
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/version.rb:72: warning: already initialized constant VERSION_PATTERN
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/requirement.rb:20: warning: already initialized constant OPS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/requirement.rb:30: warning: already initialized constant OP_RE
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/version.rb:246: warning: already initialized constant Requirement
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:18: warning: already initialized constant TYPES
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/platform.rb:171: warning: already initialized constant RUBY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/platform.rb:177: warning: already initialized constant CURRENT
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:39: warning: already initialized constant NONEXISTENT_SPECIFICATION_VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:50: warning: already initialized constant CURRENT_SPECIFICATION_VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:56: warning: already initialized constant SPECIFICATION_VERSION_HISTORY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:72: warning: already initialized constant MARSHAL_FIELDS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:75: warning: already initialized constant TODAY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/source_index.rb:593: warning: already initialized constant Cache
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:14: warning: already initialized constant DEFAULT_BACKTRACE
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:15: warning: already initialized constant DEFAULT_BENCHMARK
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:16: warning: already initialized constant DEFAULT_BULK_THRESHOLD
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:17: warning: already initialized constant DEFAULT_VERBOSITY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:18: warning: already initialized constant DEFAULT_UPDATE_SOURCES
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:24: warning: already initialized constant OPERATING_SYSTEM_DEFAULTS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:30: warning: already initialized constant PLATFORM_DEFAULTS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:53: warning: already initialized constant SYSTEM_WIDE_CONFIG_FILE
Loaded suite /home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
.
Finished in 0.136814 seconds.
 
1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:14: warning: already initialized constant VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:14: warning: already initialized constant RubyGemsVersion
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:194: warning: already initialized constant MUTEX
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:196: warning: already initialized constant RubyGemsPackageVersion
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:202: warning: already initialized constant WIN_PATTERNS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:1079: warning: already initialized constant MARSHAL_SPEC_DIR
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:1084: warning: already initialized constant YAML_SPEC_DIR
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/version.rb:72: warning: already initialized constant VERSION_PATTERN
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/requirement.rb:20: warning: already initialized constant OPS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/requirement.rb:30: warning: already initialized constant OP_RE
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/version.rb:246: warning: already initialized constant Requirement
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:18: warning: already initialized constant TYPES
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/platform.rb:171: warning: already initialized constant RUBY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/platform.rb:177: warning: already initialized constant CURRENT
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:39: warning: already initialized constant NONEXISTENT_SPECIFICATION_VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:50: warning: already initialized constant CURRENT_SPECIFICATION_VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:56: warning: already initialized constant SPECIFICATION_VERSION_HISTORY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:72: warning: already initialized constant MARSHAL_FIELDS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:75: warning: already initialized constant TODAY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/source_index.rb:593: warning: already initialized constant Cache
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:14: warning: already initialized constant DEFAULT_BACKTRACE
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:15: warning: already initialized constant DEFAULT_BENCHMARK
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:16: warning: already initialized constant DEFAULT_BULK_THRESHOLD
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:17: warning: already initialized constant DEFAULT_VERBOSITY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:18: warning: already initialized constant DEFAULT_UPDATE_SOURCES
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:24: warning: already initialized constant OPERATING_SYSTEM_DEFAULTS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:30: warning: already initialized constant PLATFORM_DEFAULTS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:53: warning: already initialized constant SYSTEM_WIDE_CONFIG_FILE
Loaded suite /home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
.......
Finished in 0.788733 seconds.
 
7 tests, 10 assertions, 0 failures, 0 errors, 0 skips
edit app/views/products/show.html.erb
<p>
  <b>Title:</b>
  <%= @product.title %>
</p>
 
<p>
  <b>Description:</b>
  <%= @product.description %>
</p>
 
<p>
  <b>Image url:</b>
  <%= @product.image_url %>
</p>
 
<p>
  <b>Price:</b>
  <%= @product.price %>
</p>
 
<%= link_to 'Edit', edit_product_path(@product) %> |
<%= link_to 'Back', products_path %>
get /products/1

Title: Pragmatic Version Control

Description: <p> This book is a recipe-based approach to using Subversion that will get you up and running quickly---and correctly. All projects need version control: it's a foundational piece of any project's infrastructure. Yet half of all project teams in the U.S. dont use any version control at all. Many others dont use it well, and end up experiencing time-consuming problems. </p>

Image url: /images/svn.jpg

Price: 0.0

Edit | Back