7.1 Iteration B1: Create the Catalog Listing 6.4 Iteration A3: Validate!
edit db/migrate/003_add_test_data.rb
class AddTestData < ActiveRecord::Migration
def self.up
Product.delete_all
Product.create(: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. don't use
any version control at all. Many others don't use it well, and end
up experiencing time-consuming problems.
</p>},
:image_url => '/images/svn.jpg',
:price => 28.50)
# . . .
end
def self.down
Product.delete_all
end
end
rake db:migrate
mv 003_add_test_data.rb 20100301000003_add_test_data.rb
(in /home/rubys/git/awdwr/work/depot)
== AddTestData: migrating ====================================================
== AddTestData: migrated (0.0636s) ===========================================
edit app/views/layouts/application.html.erb
<!DOCTYPE html>
<html>
<head>
<title>Depot</title>
<%= stylesheet_link_tag :all, 'depot' %>
<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>
</head>
edit app/views/products/index.html.erb
<div id="product-list">
<h1>Listing products</h1>
<table>
<% @products.each do |product| %>
<tr class="<%= cycle('list-line-odd', 'list-line-even') %>">
<td>
<%= image_tag product.image_url, :class => 'list-image' %>
</td>
<td class="list-description">
<dl>
<dt><%=h product.title %></dt>
<dd><%=h truncate(product.description.gsub(/<.*?>/,''),
:length => 80) %></dd>
</dl>
</td>
<td class="list-actions">
<%= link_to 'Show', product %><br/>
<%= link_to 'Edit', edit_product_path(product) %><br/>
<%= link_to 'Destroy', product,
:confirm => 'Are you sure?',
:method => :delete %>
</td>
</tr>
<% end %>
</table>
</div>
<br />
<%= link_to 'New product', new_product_path %>
cp -v /home/rubys/git/awdwr/data/images/* public/images/
`/home/rubys/git/awdwr/data/images/auto.jpg' -> `public/images/auto.jpg'
`/home/rubys/git/awdwr/data/images/logo.gif' -> `public/images/logo.gif'
`/home/rubys/git/awdwr/data/images/logo.jpg' -> `public/images/logo.jpg'
`/home/rubys/git/awdwr/data/images/logo.png' -> `public/images/logo.png'
`/home/rubys/git/awdwr/data/images/rails.png' -> `public/images/rails.png'
`/home/rubys/git/awdwr/data/images/svn.jpg' -> `public/images/svn.jpg'
`/home/rubys/git/awdwr/data/images/utc.jpg' -> `public/images/utc.jpg'
cp -v /home/rubys/git/awdwr/data/depot.css public/stylesheets
`/home/rubys/git/awdwr/data/depot.css' -> `public/stylesheets/depot.css'
get /products
![]() |
|
Show Edit Destroy |
![]() |
|
Show Edit Destroy |
![]() |
|
Show Edit Destroy |
7.1 Iteration B1: Create the Catalog Listing 6.4 Iteration A3: Validate!