Ruby Build a Todo List Application with Rails 4 Build a Todo List Application with Rails 4 Marking Todo Items Complete

Joshua Atteberry
Joshua Atteberry
6,250 Points

The action 'show' could not be found for TodoItemsController

This error shows up when I run my spec and also when I click "Mark Complete" on the page.

complete_spec.rb

it "is successful when marking a single item complete" do
    expect(todo_item.completed_at).to be_nil
    visit_todo_list todo_list
    within dom_id_for(todo_item) do
      click_link "Mark Complete"
    end
    todo_item.reload
    expect(todo_item.completed_at).to_not be_nil
  end

todo_items_controller.rb

def complete
    @todo_item = @todo_list.todo_items.find(params[:id])
    @todo_item.update_attribute(:completed_at, Time.now)
    redirect_to todo_list_todo_item_path, notice: "Todo item marked as complete"
end

todo_items/index.html.erb

<%= link_to "Mark Complete", complete_todo_list_todo_item_path(todo_item), method: :patch %>

2 Answers

Maciej Czuchnowski
Maciej Czuchnowski
36,429 Points

In this line:

redirect_to todo_list_todo_item_path, notice: "Todo item marked as complete"

You specified that you want show path for one item (todo_list_todo_item_path), but did not pass any item inside or any list as arguments.You can also redirect to the item index for this particular list: todo_list_todo_items_path(@todo_list) (notice plural of 'items' - these things matter).

Joshua Atteberry
Joshua Atteberry
6,250 Points

Thank you, adding an 's' worked. I'm always messing up my plurals!

Aidan O'Leary
Aidan O'Leary
12,313 Points

Thanks it worked for me as well.