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.
rails -v Rails 2.3.3
ruby script/generate resource Resource first_name:string last_name:string
exists app/models/
exists app/controllers/
exists app/helpers/
create app/views/resources
exists test/functional/
exists test/unit/
create test/unit/helpers/
dependency model
exists app/models/
exists test/unit/
exists test/fixtures/
create app/models/resource.rb
create test/unit/resource_test.rb
create test/fixtures/resources.yml
create db/migrate
create db/migrate/20091229144907_create_resources.rb
create app/controllers/resources_controller.rb
create test/functional/resources_controller_test.rb
create app/helpers/resources_helper.rb
create test/unit/helpers/resources_helper_test.rb
route map.resources :resources
This RailsGuides link shows a description for each file produced when generating a resource.
ruby script/generate scaffold Scaffold title:string order:integer
exists app/models/
exists app/controllers/
exists app/helpers/
create app/views/scaffolds
exists app/views/layouts/
exists test/functional/
exists test/unit/
exists test/unit/helpers/
exists public/stylesheets/
create app/views/scaffolds/index.html.erb
create app/views/scaffolds/show.html.erb
create app/views/scaffolds/new.html.erb
create app/views/scaffolds/edit.html.erb
create app/views/layouts/scaffolds.html.erb
create public/stylesheets/scaffold.css
create app/controllers/scaffolds_controller.rb
create test/functional/scaffolds_controller_test.rb
create app/helpers/scaffolds_helper.rb
create test/unit/helpers/scaffolds_helper_test.rb
route map.resources :scaffolds
dependency model
exists app/models/
exists test/unit/
exists test/fixtures/
create app/models/scaffold.rb
create test/unit/scaffold_test.rb
create test/fixtures/scaffolds.yml
exists db/migrate
create db/migrate/20091229145313_create_scaffolds.rb
Tags: resource, restful, ruby on rails, scaffold, view

Entries (RSS)