I finished my first app last week. This app basically is my personal blog. I hope to maintain and add features to it in the days to come. Today though, I started with a new project - a todo list. The first thing I did for this project was
rails g scaffold todo_list title:string description:text. And with it, I had used the scaffold for the first time. There was one thing I wanted to do though, I really wanted to understand how the scaffold worked.
Here's my understanding of how the scaffold works. Upon creating the new scaffold with the above command, it did a couple of things for me.
It generated the routes for me in the
routes.rbfile in the config folder. Viewing the
routes.rbfile in my editor, I could see
resources :todo_liston the file.
It generated a model TodoList and once after migrating the database via 'rails db:migrate` the database was ready to be used. The model had a title and description because I had set those two parameters when creating the scaffold.
Scaffold also generated all the controllers for the CRUD methods. Meaning from the get-go I would be able to perform create, read, update and deletion of entries.
Finally, all the views were generated, and the views had a form with title and description. Also since the controllers had already defined the CRUD methods, I was able to create, delete, edit and see my entries.
It was that easy. My entire last week's work summarised by one syntax. 😵😵😵😵
Still, last week was a great learning experience for me building everything from scratch, and this week as I delve into the scaffold generated code, I will really read between the lines of codes and understand what it does.