These instructions use an example database table named… orders
Model
- “ruby script/generate model order” (Note – use the singular name “order”, not “orders”)
- “ruby script/generate scaffold order” (This will create BOTH the Model and Controller and will implement the basic Scaffold functionality as your base code)
- This command also creates the following files:
- app/models/ order.rb
- test/unit/ order_test.rb
- test/fixtures/ orders.yml
Controller
- “ruby script/generate controller order index” (Note – use the singular name “order”, not “orders”)
- creates…
- app/contollers/orders_controller.rb
- app/helpers/orders_controller.rb
- app/views/orders/index.rhtml
- test/functional/orders_controller_test.rb
View
- Automatically created in the Controller step above.
- To manually create
- create a folder: app/views/orders/
- create a file: index.rhtml (in the new folder)
Test It
ruby script/server (Note – Ruby command line, from the “application” folder)
http://localhost:3000/orders (Note – “orders” is the name of the “view folder”. This will display the “index.rhtml” file by default)