Rails resource vs Rails scaffold

Rails resource vs Rails scaffold

What’s the difference between a scaffold and resource in Ruby on Rails? Essentially, the only difference is that the views (and associated layout and css file) for index, show, new and edit are created. The output when generating both the scaffold and the resource (with the command line generator) are shown below.

Also, both are created as RESTful resources, which means the “map.resources” line is included in the routes.rb file. This line is shown in the Rails output below.

ruby

  1. rails -v
  2. Rails 2.3.3

 

ruby

  1. ruby script/generate resource Resource first_name:string last_name:string
  2.       exists  app/models/
  3.       exists  app/controllers/
  4.       exists  app/helpers/
  5.       create  app/views/resources
  6.       exists  test/functional/
  7.       exists  test/unit/
  8.       create  test/unit/helpers/
  9.   dependency  model
  10.       exists    app/models/
  11.       exists    test/unit/
  12.       exists    test/fixtures/
  13.       create    app/models/resource.rb
  14.       create    test/unit/resource_test.rb
  15.       create    test/fixtures/resources.yml
  16.       create    db/migrate
  17.       create    db/migrate/20091229144907_create_resources.rb
  18.       create  app/controllers/resources_controller.rb
  19.       create  test/functional/resources_controller_test.rb
  20.       create  app/helpers/resources_helper.rb
  21.       create  test/unit/helpers/resources_helper_test.rb
  22.        route  map.resources :resources

This RailsGuides link shows a description for each file produced when generating a resource.

ruby

  1. ruby script/generate scaffold Scaffold title:string order:integer
  2.       exists  app/models/
  3.       exists  app/controllers/
  4.       exists  app/helpers/
  5.       create  app/views/scaffolds
  6.       exists  app/views/layouts/
  7.       exists  test/functional/
  8.       exists  test/unit/
  9.       exists  test/unit/helpers/
  10.       exists  public/stylesheets/
  11.       create  app/views/scaffolds/index.html.erb
  12.       create  app/views/scaffolds/show.html.erb
  13.       create  app/views/scaffolds/new.html.erb
  14.       create  app/views/scaffolds/edit.html.erb
  15.       create  app/views/layouts/scaffolds.html.erb
  16.       create  public/stylesheets/scaffold.css
  17.       create  app/controllers/scaffolds_controller.rb
  18.       create  test/functional/scaffolds_controller_test.rb
  19.       create  app/helpers/scaffolds_helper.rb
  20.       create  test/unit/helpers/scaffolds_helper_test.rb
  21.        route  map.resources :scaffolds
  22.   dependency  model
  23.       exists    app/models/
  24.       exists    test/unit/
  25.       exists    test/fixtures/
  26.       create    app/models/scaffold.rb
  27.       create    test/unit/scaffold_test.rb
  28.       create    test/fixtures/scaffolds.yml
  29.       exists    db/migrate
  30.       create    db/migrate/20091229145313_create_scaffolds.rb
Share