Scaffolding in Ruby on Rails refers to the of a set of a model, views and a controller usually used for a single database table. auto-generation For example, you can auto-generate a ready to use controller, model, and views with a full ( reate, ead, pdate, elete) web interface for the Story table using the following command: CRUD C R U D $rails scaffold Story title: content:text generate string It's way easier to do this, instead of coding everything yourself, it saves you a lot of time! Scaffold or Models? Compared to the that generates everything that you need (and don't need), create only some related components. The best, and my favorite, way to explain the difference between scaffold and models is by using the following example: scaffold models Generate models Once you enter the command $rails model Story title: content:text generate string you will generate: invoke active_record create db/migrate/20180205103025_create_stories.rb create app/models/story.rb test_unit create test/models/story_test.rb create test/fixtures/stories.yml invoke will tie your model to the database, while the next line creates . Migrations are used to alter your database schema. This migration file creates the database table called 'stories', and database columns for "title" and "content". invoke active_record a migration file The third line will create a - a Ruby class that inherits the Active Record. With this, every method that can be called in Active Record can now be called in your model. The last three lines create related for your model. model test files While scaffolding will get you up and running quickly, the code it generates is unlikely to be a perfect fit for your application. You’ll most probably want to customize the generated code. Many experienced Rails developers avoid scaffolding entirely, preferring to write all or most of their source code from scratch. You can read more about this on . RailsGuides As you can see, does not create any kind of view to display information on a page. To have a complete, ready to use application, you would need to: generate models (which in turn generates views, as well) or generate controllers (which generates your model, views, controller and writes to your routes.rb file). generate scaffold If you change your mind and decide to use scaffold after already generating the model, you can always run $rails scaffold <name> generate It will create all the missing files. Generate scaffold If you enter the command $rails scaffold Story title: content:text generate string you will generate the following files: invoke active_record create db/migrate/20180205103508_create_stories.rb create app/models/story.rb test_unit create test/models/story_test.rb create test/fixtures/stories.yml resource_route route resources scaffold_controller create app/controllers/stories_controller.rb erb create app/views/stories create app/views/stories/index.html.erb create app/views/stories/edit.html.erb create app/views/stories/show.html.erb create app/views/stories/new.html.erb create app/views/stories/_form.html.erb test_unit create test/controllers/stories_controller_test.rb helper create app/helpers/stories_helper.rb test_unit jbuilder create app/views/stories/index.json.jbuilder create app/views/stories/show.json.jbuilder create app/views/stories/_story.json.jbuilder assets coffee create app/assets/javascripts/stories.coffee scss create app/assets/stylesheets/stories.scss scss create app/assets/stylesheets/scaffolds.scss invoke invoke :stories invoke invoke invoke invoke invoke invoke invoke invoke invoke invoke Once model related tests are created, the next line will to your stories. After generating resource routes comes the and its actions (index, show, new, edit, create, update and destroy), together with and for each of this actions. generate resource routes controller views controller tests The Rails router recognizes URLs and connects them to a controller's action. By default, a controller's action will render a view of the same name. Migration Every time you create a using scripts (generate model/generate scaffold) a new migration is added to the correct directory. You use migration db:migrate $rake to checks which migrations that have not been added to the database. create == 20180205103508 CreateStories: migrating ==================================== -- _table(:stories) -> 0.0007s == 20180205103508 CreateStories: migrated (0.0008s) =========================== Destroy Everyone is free to edit and do the necessary changes to their application to work as intended, even if it means completely . You can remove scaffold in the following way: removing scaffold Generate scaffold: $rails generate scaffold Story If you migrated your files, perform a rollback: $rake db:rollback Destroy or undo scaffold: $rails destroy scaffold Story By doing this, you will delete all the files created by the scaffold but additional changes that you may have done manually will not be removed. Conclusion A scaffold is excellent to use when it comes to . However, be sure to generate your own models when you decide to develop a new application. Don't forget to always test your application, find out how to do it by using ! simple examples, quick mockups or testing Capybara We hope you discovered something new today! Previously published at https://kolosek.com/rails-scaffold/