6.2 Creating the Products Model and Maintenance Application 6.1 Iteration A1: Getting Something Running
ls -p
app/ db/ lib/ public/ README test/ vendor/
config/ doc/ log/ Rakefile script/ tmp/
ruby script/generate scaffold product title:string description:text image_url:string
exists app/models/
exists app/controllers/
exists app/helpers/
create app/views/products
exists app/views/layouts/
exists test/functional/
exists test/unit/
create test/unit/helpers/
exists public/stylesheets/
create app/views/products/index.html.erb
create app/views/products/show.html.erb
create app/views/products/new.html.erb
create app/views/products/edit.html.erb
create app/views/layouts/products.html.erb
create public/stylesheets/scaffold.css
create app/controllers/products_controller.rb
create test/functional/products_controller_test.rb
create app/helpers/products_helper.rb
create test/unit/helpers/products_helper_test.rb
route map.resources :products
dependency model
exists app/models/
exists test/unit/
exists test/fixtures/
create app/models/product.rb
create test/unit/product_test.rb
create test/fixtures/products.yml
create db/migrate
create db/migrate/20100301051029_create_products.rb
rake db:migrate
mv 20100301051029_create_products.rb 20100301000001_create_products.rb
(in /home/rubys/git/awdwr/work-188-235/depot)
== CreateProducts: migrating =================================================
-- create_table(:products)
-> 0.0018s
== CreateProducts: migrated (0.0019s) ========================================
sqlite3> select version from schema_migrations
version = 20100301000001
edit app/views/products/new.html.erb
<h1>New product</h1>
<% form_for(@product) do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :title %><br />
<%= f.text_field :title %>
</p>
<p>
<%= f.label :description %><br />
<%= f.text_area :description, :rows => 6 %>
</p>
<p>
<%= f.label :image_url %><br />
<%= f.text_field :image_url %>
</p>
<p>
<%= f.submit 'Create' %>
</p>
<% end %>
<%= link_to 'Back', products_path %>
get /products
get /products/new
post /products
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 | Backget /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 |
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
/home/rubys/.rvm/rubies/ruby-1.8.8-r26786/bin/ruby -I"lib:test" "/home/rubys/.rvm/gems/ruby-1.8.8-r26786%global/gems/rake-0.8.7/lib/rake/rake_test_loader.rb" "test/unit/helpers/products_helper_test.rb" "test/unit/product_test.rb"
(in /home/rubys/git/awdwr/work-188-235/depot)
Loaded suite /home/rubys/.rvm/gems/ruby-1.8.8-r26786%global/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
.
Finished in 0.038164 seconds.
1 tests, 1 assertions, 0 failures, 0 errors
/home/rubys/.rvm/rubies/ruby-1.8.8-r26786/bin/ruby -I"lib:test" "/home/rubys/.rvm/gems/ruby-1.8.8-r26786%global/gems/rake-0.8.7/lib/rake/rake_test_loader.rb" "test/functional/products_controller_test.rb"
Loaded suite /home/rubys/.rvm/gems/ruby-1.8.8-r26786%global/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
.......
Finished in 0.148662 seconds.
7 tests, 10 assertions, 0 failures, 0 errors
/home/rubys/.rvm/rubies/ruby-1.8.8-r26786/bin/ruby -I"lib:test" "/home/rubys/.rvm/gems/ruby-1.8.8-r26786%global/gems/rake-0.8.7/lib/rake/rake_test_loader.rb"
6.2 Creating the Products Model and Maintenance Application 6.1 Iteration A1: Getting Something Running