Agile Web Development with Rails - Chapter 6
Source Code depot1〜depot4
6.1 Iteration A1: Get Something Running
Create a Rails Application
toward@localmachine ~/rails $ rails depot toward@localmachine ~/rails $ cd depot/
Configure the Application (順番入れ替え)
MySQL Administratorでデータベースdepot_developmentを作成
config/database.ymlを変更
login: &login adapter: mysql username: root password: xxxx host: LOCALHOST development: database: depot_development <<: *login test: database: depot_test <<: *login production: database: depot_production <<: *login
Create the Product Table (順番入れ替え)
Migration
toward@localmachine ~/rails/depot $ ruby script/generate migration InitialScheme create db/migrate create db/migrate/001_initial_scheme.rb
db/migrate/001_initial_scheme.rb 変更
class InitialScheme < ActiveRecord::Migration def self.up create_table :products do |t| t.column :title, :string, :limit => 100, :null => false t.column :description, :text, :null => false t.column :image_url, :string, :limit => 200, :null => false t.column :price, :float, :null => false end end def self.down drop_table :products end end
toward@localmachine ~/rails/depot $ rake --trace migrate (in /home/toward/rails/depot) ** Invoke migrate (first_time) ** Invoke environment (first_time) ** Execute environment ** Execute migrate
Create the Maintenance Application
toward@localmachine ~/rails/depot $ ruby script/generate scaffold Product Admin exists app/controllers/ exists app/helpers/ create app/views/admin exists test/functional/ 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 app/views/admin/_form.rhtml create app/views/admin/list.rhtml create app/views/admin/show.rhtml create app/views/admin/new.rhtml create app/views/admin/edit.rhtml create app/controllers/admin_controller.rb create test/functional/admin_controller_test.rb create app/helpers/admin_helper.rb create app/views/layouts/admin.rhtml create public/stylesheets/scaffold.css toward@localmachine ~/rails/depot $ ruby script/server => Booting WEBrick... => Rails application started on http://0.0.0.0:3000 => Ctrl-C to shutdown server; call with --help for options [2005-12-18 00:16:45] INFO WEBrick 1.3.1 [2005-12-18 00:16:45] INFO ruby 1.8.3 (2005-09-21) [i386-cygwin] [2005-12-18 00:16:45] INFO WEBrick::HTTPServer#start: pid=4008 port=3000
6.2 Iteration A2: Add a Missing Column
toward@localmachine ~/rails/depot $ ruby script/generate migration AddProductDateAvailable exists db/migrate create db/migrate/002_add_product_date_available.rb
db/migrate/002_add_product_date_available.rb 変更
class AddProductDateAvailable < ActiveRecord::Migration def self.up add_column :products, :date_available, :datetime, :null => false end def self.down remove_column :products, :date_available end end
toward@localmachine ~/rails/depot $ rake --trace migrate (in /home/toward/rails/depot) ** Invoke migrate (first_time) ** Invoke environment (first_time) ** Execute environment ** Execute migrate
toward@localmachine ~/rails/depot $ ruby script/generate scaffold Product Admin exists app/controllers/ exists app/helpers/ exists app/views/admin exists test/functional/ dependency model exists app/models/ exists test/unit/ exists test/fixtures/ identical app/models/product.rb identical test/unit/product_test.rb identical test/fixtures/products.yml overwrite app/views/admin/_form.rhtml? [Ynaq] a forcing scaffold force app/views/admin/_form.rhtml identical app/views/admin/list.rhtml identical app/views/admin/show.rhtml identical app/views/admin/new.rhtml identical app/views/admin/edit.rhtml identical app/controllers/admin_controller.rb identical test/functional/admin_controller_test.rb identical app/helpers/admin_helper.rb identical app/views/layouts/admin.rhtml identical public/stylesheets/scaffold.css