レイルに乗ってみた〜 目次
書籍『Rails of Ruby on Rails ~Case of LOCUSANDWONDERS.COM~』で勉強してみた(P127〜)
モデルを作成
G5:~/work/locus username$ script/generate model genre exists app/models/ exists test/unit/ exists test/fixtures/ create app/models/genre.rb create test/unit/genre_test.rb create test/fixtures/genres.yml exists db/migrate create db/migrate/20080918094032_create_genres.rb Loaded suite script/generate Started Finished in 0.000847 seconds. 0 tests, 0 assertions, 0 failures, 0 errors
モデルの修正
書籍の通りなので略。
マイグレーションファイル修正
書籍の通りなので略。
マイグレーション実行
G5:~/work/locus username$ rake db:migrate (in /Users/username/work/locus) == 20080918094032 CreateGenres: migrating ===================================== -- create_table(:genres) -> 0.0175s -- add_column(:products, :genre_id, :integer) -> 0.5096s == 20080918094032 CreateGenres: migrated (0.5338s) ============================ Loaded suite /opt/local/bin/rake Started Finished in 0.001115 seconds. 0 tests, 0 assertions, 0 failures, 0 errors
Genresコントローラ作成
G5:~/work/locus username$ script/generate controller admin/genres exists app/controllers/admin exists app/helpers/admin create app/views/admin/genres exists test/functional/admin create app/controllers/admin/genres_controller.rb create test/functional/admin/genres_controller_test.rb create app/helpers/admin/genres_helper.rb Loaded suite script/generate Started Finished in 0.000748 seconds. 0 tests, 0 assertions, 0 failures, 0 errors
/work/locus/app/controllers/admin/genres_controller.rbの修正は書籍の通りなので略。
Productsコントローラの修正
書籍の通りなので略。
ブラウザで確認
http://localhost:3000/admin/genres
http://localhost:3000/admin/products
表示が若干違うが...まあいいか(・∀・)