Try the scaffold generator:
rails generate scaffold task title:string description:text complete:boolean
Compare the output with the draft:resource generator's output.
Start your server and visit /tasks. Test it out.
Do you understand every line of scaffold? Ask lots of questions.
Add a presence validation to the title column of tasks. Test it out.
Add Devise and try generating a Devise model.
rails g devise user first_name:string last_name:string
This does something similar to rails g draft:account, but a lot better. Try out the current_user helper method that Devise provides.
- Add a navbar with sign up, sign in, edit profile, and sign out links.
- While we're at it, add flash messages to the application layout.
- Make the necessary changes to allow
first_nameandlast_nameto be set via the sign up/edit profile forms.
rails g migration AddUserIdToTasks user:belongs_to
- A user has many tasks.
- A task belongs to a user.
Try out the create action. It won't work right away — why?
Fix it.
Only display the signed in user's tasks on the home page.
-
Add the column:
rails g migration AddTasksCountToUsers tasks_count:integer -
Add the
:counter_cacheoption tobelongs_to:belongs_to :user, counter_cache: true
- Make the
tasks#create,tasks#update, andtasks#destroyactions redirect to/tasks#indexinstead oftasks#show.