The Depot Application

The Depot Application

6.3 Iteration A2: Add a Missing Column 6.1 Iteration A1: Getting Something Running

6.2 Creating the Products Model and Maintenance Application

ls -p
app/	 config.ru  doc/     Gemfile.lock  log/     Rakefile  script/  tmp/
config/  db/	    Gemfile  lib/	   public/  README    test/    vendor/
rails generate scaffold product title:string description:text image_url:string
      invoke  active_record
      create    db/migrate/20100906011101_create_products.rb
      create    app/models/product.rb
      invoke    test_unit
      create      test/unit/product_test.rb
      create      test/fixtures/products.yml
       route  resources :products
      invoke  scaffold_controller
      create    app/controllers/products_controller.rb
      invoke    erb
      create      app/views/products
      create      app/views/products/index.html.erb
      create      app/views/products/edit.html.erb
      create      app/views/products/show.html.erb
      create      app/views/products/new.html.erb
      create      app/views/products/_form.html.erb
      invoke    test_unit
      create      test/functional/products_controller_test.rb
      invoke    helper
      create      app/helpers/products_helper.rb
      invoke      test_unit
      create        test/unit/helpers/products_helper_test.rb
      invoke  stylesheets
      create    public/stylesheets/scaffold.css
rake db:migrate
mv 20100906011101_create_products.rb 20100301000001_create_products.rb
(in /home/rubys/git/awdwr/work/depot)
==  CreateProducts: migrating =================================================
-- create_table(:products)
   -> 0.0018s
==  CreateProducts: migrated (0.0019s) ========================================
 
sqlite3> select version from schema_migrations
version = 20100301000001

Start the server.

edit app/views/products/_form.html.erb
<%= form_for(@product) do |f| %>
  <% if @product.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@product.errors.count, "error") %> prohibited this product from being saved:</h2>
 
      <ul>
      <% @product.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>
 
  <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="actions">
    <%= f.submit %>
  </div>
<% end %>
get /products

Listing products

Title Description Image url

New Product
get /products/new

New product




Back
post /products
You are being redirected.
get http://localhost:3000/products/1

Product was successfully created.

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

Edit | Back
get /products

Listing products

Title Description Image url
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 Show Edit Destroy

New Product
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);
CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL);
CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version");
rake test
(in /home/rubys/git/awdwr/work/depot)
Loaded suite /home/rubys/.rvm/gems/ruby-1.8.7-p302/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
.
Finished in 0.020159 seconds.
 
1 tests, 1 assertions, 0 failures, 0 errors
Loaded suite /home/rubys/.rvm/gems/ruby-1.8.7-p302/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
.......
Finished in 0.15268 seconds.
 
7 tests, 10 assertions, 0 failures, 0 errors

6.3 Iteration A2: Add a Missing Column 6.1 Iteration A1: Getting Something Running