レイルに乗ってみた〜 目次
書籍『Rails of Ruby on Rails ~Case of LOCUSANDWONDERS.COM~』で勉強してみた(p102〜)
トラックバック機能
躓くとこも無く、ほぼ書籍のまま。これまでの作業を繰り返してる感じ。
なので、気になったとこだけメモ。詳細は書籍を参照。
スキャフォールドでベース生成
~/work/locus $ script/generate scaffold Trackback title:string: excerpt:text url:string blog_name:string entry:references exists app/models/ exists app/controllers/ exists app/helpers/ create app/views/trackbacks exists app/views/layouts/ exists test/functional/ exists test/unit/ exists public/stylesheets/ create app/views/trackbacks/index.html.erb create app/views/trackbacks/show.html.erb create app/views/trackbacks/new.html.erb create app/views/trackbacks/edit.html.erb create app/views/layouts/trackbacks.html.erb overwrite public/stylesheets/scaffold.css? (enter "h" for help) [Ynaqdh] n skip public/stylesheets/scaffold.css create app/controllers/trackbacks_controller.rb create test/functional/trackbacks_controller_test.rb create app/helpers/trackbacks_helper.rb route map.resources :trackbacks dependency model exists app/models/ exists test/unit/ exists test/fixtures/ create app/models/trackback.rb create test/unit/trackback_test.rb create test/fixtures/trackbacks.yml exists db/migrate create db/migrate/20080910062530_create_trackbacks.rb Loaded suite script/generate Started Finished in 0.000447 seconds. 0 tests, 0 assertions, 0 failures, 0 errors
マイグレーション実行
~/work/locus $ rake db:migrate (in /Users/username/work/locus) == 20080910062530 CreateTrackbacks: migrating ================================= -- create_table(:trackbacks) -> 0.0375s -- add_column(:entries, :trackbacks_count, :integer, {:default=>0}) -> 0.0262s -- add_index(:trackbacks, :entry_id) -> 0.0077s == 20080910062530 CreateTrackbacks: migrated (0.0725s) ======================== Loaded suite /opt/local/bin/rake Started Finished in 0.000448 seconds. 0 tests, 0 assertions, 0 failures, 0 errors
保存時に加工処理を追加
app/models/trackback.rbを修正
ネステッドルート
ここ削除でよいよね?
map.resources :trackbacks
トラックバック機能をブラウザで確認してみた
メモ
script/generate〜やrake〜などは、eshellとか同一のウインドウで処理すると見直し楽かも。