Open Step 3: Create the Task Resource
Now, we could take the easy way out and generate a rails scaffold instead of a resource, which will set up everything for us, including the routes, controller actions, views, style, etc. However, we want to really learn how to build this task manager step-by-step, so we will take the long and hard route. I promise that it's worth the effort, and you will learn a lot in the process.
What's a resource? A resource is any object that you want users to be able to access via URI and perform CRUD (create, read, update, delete) operations on.
We need a Task resource for our to-do list, which has description
and completed
attributes. So let’s generate the Task
model using the rails generate resource
command. This command creates an empty model, controller, and migration to create the tasks
table.
➜ bin/rails generate resource task description:string{200} completed:boolean
Running this command will create a 20220212031029_create_tasks.rb
migration file under the db/migrate
d