Scaffolding in Ruby on Rails is a neat way to automatically generate a base set of view, along with a model and controller. It is a great way to save some time from writing out tedious code every time you are starting on a new application and want a quick way of generating some code.
Scaffolding is a feature in Ruby on Rails that automatically generates the following:
-
A controller
-
A model and migration files
-
A route added to config/routes.rb
-
A set of views
-
A set of files for testing
These features are generated by the command
rails generate scaffold
where the generate can be shortened to g and the statement is followed by the name
of what you want constructed, for example:
rails g scaffold articles
The biggest advantage of using the scaffold is it certainly saves some time from producing the views, controller, and what not yourself. It gives some consistency in the sense that you will know exactly what it creates every time no matter what. It is often used as a learning tool so to avoid the overwhelming feeling of all the moving parts and to save some time and jump into simple examples.
However, the clear disadvantage is that while scaffolding is perfectly acceptable if spinning up a quick application is exactly what you need, there is more advantages in generating models yourself. If you are developing a new application, it is generally advised you generate all the compononents yourself so that you are comfortable with the application structure and that you can make small individual changes easily by implementing them yourself!
Overall, try out scaffolding yourself and see how it compares to generating the components yourself.