October 2008
Beginner to intermediate
224 pages
5h 34m
English
Whew. That section had a lot of detail. Now we have only to scaffold the last resource for categories and create the test data for slideshows and categories. Generate the scaffold for categories now with the following command in your terminal:
$ script/generate scaffold category parent_id:integer name:string
...
create app/views/categories
create app/views/categories/index.html.erb
create app/views/categories/show.html.erb
create app/views/categories/new.html.erb
create app/views/categories/edit.html.erb
create app/views/layouts/categories.html.erb
identical public/stylesheets/scaffold.css
create app/controllers/categories_controller.rb
create test/functional/categories_controller_test.rb
create app/helpers/categories_helper.rb
route map.resources :categories
dependency model
...
create app/models/category.rb
create test/unit/category_test.rb
create test/fixtures/categories.yml
create db/migrate/20080509013624_create_categories.rbRails creates the usual suspects. We’ve shortened the listing, but
you get the idea. Rails creates your controller, views, a named route, and
test code for Category. As always,
create the test fixtures with the data below.
text/fixtures/slideshows.yml should like like the
following:
slideshow_1: id: 1 name: Interesting Pictures
and text/fixtures/categories.yml should look like
the following:
category_1: id: 1 name: All category_2: id: 2 parent_id: 1 name: People category_3: id: 3 parent_id: 1 name: Animals category_4: id: 4 parent_id: ...
Read now
Unlock full access