コントローラーとビュー
- Memoモデルを読み書きするコントローラーとビューを作る
-
scaffold(スカッフォルド:足場)ジェネレータ
-
モデルを元に、そのモデルを読み書きするコントローラーとビューを自動生成する
./script/generate scaffold memo memo exists app/controllers/ exists app/helpers/ create app/views/memo exists app/views/layouts/ exists test/functional/ dependency model exists app/models/ exists test/unit/ exists test/fixtures/ identical app/models/memo.rb identical test/unit/memo_test.rb skip test/fixtures/memos.yml create app/views/memo/_form.rhtml create app/views/memo/list.rhtml create app/views/memo/show.rhtml create app/views/memo/new.rhtml create app/views/memo/edit.rhtml create app/controllers/memo_controller.rb create test/functional/memo_controller_test.rb create app/helpers/memo_helper.rb create app/views/layouts/memo.rhtml create public/stylesheets/scaffold.css
-
モデルを元に、そのモデルを読み書きするコントローラーとビューを自動生成する
- Memoコントローラが生成された
- モデル、ビュー、コントローラの3つが揃った
実行してみる
./script/server => Booting WEBrick... => Rails application started on http://0.0.0.0:3000 => Ctrl-C to shutdown server; call with --help for options [2007-05-12 21:32:35] INFO WEBrick 1.3.1 [2007-05-12 21:32:35] INFO ruby 1.8.5 (2006-08-25) [i386-linux] [2007-05-12 21:32:35] INFO WEBrick::HTTPServer#start: pid=4151 port=3000 127.0.0.1 - - [12/May/2007:21:32:51 JST] "GET / HTTP/1.1" 200 7552 - -> /
実行画面
http://localhost:3000/memo
-
New Memo画面
-
編集画面
-
メモリスト