Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

scaffolding
rails

What is Scaffolding in Rails6?

Ammar Ahmad Farid

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Scaffolding is the automatic generation of a simple set of a models, views, and controllers.

Let’s build an app in Rails6

Try the following commands in the terminal:

rails new newspaperstand

The above command will create the new newspaperstand project.

Go to the project directory.

cd newspaperstand

Before writing more code for the app, you need to create amodel and controllers using the rails generate command.

Create a model newspaper with the attributes (headline and publisher).

rails generate newspaper headline: string publisher: string
rails generate controller newspaper

Scaffolding can do all the work above in a single command.

Go ahed and try it in the terminal below.

rails new newspaperstand
cd newspaperstand
rails generate scaffold newspaper headline:text publisher:string
Terminal 1
Terminal

Your terminal output should be same as the output shown below:

Running via Spring preloader in process 188
      invoke  active_record
      create    db/migrate/20211011112059_create_newspapers.rb
      create    app/models/newspaper.rb
      invoke    test_unit
      create      test/models/newspaper_test.rb
      create      test/fixtures/newspapers.yml
      invoke  resource_route
       route    resources :newspapers
      invoke  scaffold_controller
      create    app/controllers/newspapers_controller.rb
      invoke    erb
      create      app/views/newspapers
      create      app/views/newspapers/index.html.erb
      create      app/views/newspapers/edit.html.erb
      create      app/views/newspapers/show.html.erb
      create      app/views/newspapers/new.html.erb
      create      app/views/newspapers/_form.html.erb
      invoke    test_unit
      create      test/controllers/newspapers_controller_test.rb
      create      test/system/newspapers_test.rb
      invoke    helper
      create      app/helpers/newspapers_helper.rb
      invoke      test_unit
      invoke    jbuilder
      create      app/views/newspapers/index.json.jbuilder
      create      app/views/newspapers/show.json.jbuilder
      create      app/views/newspapers/_newspaper.json.jbuilder
      invoke  assets
      invoke    scss
      create      app/assets/stylesheets/newspapers.scss
      invoke  scss
   identical    app/assets/stylesheets/scaffolds.scss

RELATED TAGS

scaffolding
rails

CONTRIBUTOR

Ammar Ahmad Farid
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring