Add the migration:
bin/rails generate migration add_completed_at_to_todo_items
Add this to the (db) migration:
class AddCompletedAtToTodoItems < ActiveRecord::Migration def change add_column :todo_items :completed_at, :datetime end end
Run:
bin/rake db:migrate
And for the tests as well:
bin/rake db:migrate RAILS_ENV=test
We create a new file called complete_spec.rb under >spec >todo_items:
Now we need to add a route and a controller action.
Let's start with the route for marking a todo item complete:
* When we want to update something, we use the patch http.
resources :todo_lists do resources :todo_items do member do patch :mark_complete end end end
Now we add the "Complete" option to our views (notice we need to add the "patch" method:
<%= link_to "Mark Complete", complete_todo_list_todo_item_path(todo_item), method: :patch
Now we need to go to the Controller:
def complete @todo_item = @todo_list.todo_items.find(params[:id]) @todo_item.update_attribute(:completed_at, Time.now) redirect_to todo_list_todo_items_path, notice: "Todo item marked as complete." end