Scaffolding is a great feature of Rails for individuals new to the development, or perhaps those just new to Rails itself. Scaffolding is one of the many generate commands that allows you to automatically create all the framework files you need for a simple object, including the model, controller, database migration file, and basic views.
For example, if you want to create a simple Book model and all associated components, you might run the following command in the terminal.
Here we’re asking rails to generate a scaffold object called Book and then specifying the model fields afterward in the format of field_name:data_type.
You should immediately see an output with all the generates files and paths.
Believe it or not, you now technically have a working rails application! You can run your rails server ($ rails s) and browse to your localhost to see your functional page. It won’t be pretty, but as is the beauty of Rails, it should just work out of the box with the fields behaving as you expect.
While scaffolding is a great jumping-off point for developers still learning Rails, much of the code generated by the scaffold command will be wasted or not appropriate for most projects, so be weary of all the files and code created when running this command in your own projects.
Leave a Reply