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.rb
file in the config folder. Viewing theroutes.rb
file in my editor, I could seeresources :todo_list
on 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.
Top comments (1)
Nice post!
I find that Rails make it easy to "bootstrap" things, but what makes it challenging for me, coming from Node and Python, are the assumptions and things work out-of-the-box which gets hard to trace
E.g.
Having scaffolded "Item"
The route /items and /items.json just work without any code to render the page/json explicitly (maybe i'm wrong about this)
Keep us posted on your journey to learn Rails :)