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

Miroslav Králik
Miroslav Králik
7,807 Points

No route matches [GET] "/todo_lists/1/todo_items/1/complete"

I am getting the following error:

Marking todo items as complete is successul when marking a single todo item complete (FAILED - 1)

Failures:
  1) Marking todo items as complete is successul when marking a single todo item complete
     Failure/Error: click_link "Mark Complete"
     ActionController::RoutingError:
       No route matches [GET] "/todo_lists/1/todo_items/1/complete"
     # ./spec/features/todo_items/complete_spec.rb:13:in `block (3 levels) in <top (required)>'
     # ./spec/features/todo_items/complete_spec.rb:12:in `block (2 levels) in <top (required)>'

any idea?

Here is my 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

and here is route:

  resources :todo_lists do
      resources :todo_items do
        member do
          patch :complete
        end
      end
  end

Thanks, Miroslav

Maciej Czuchnowski
Maciej Czuchnowski
36,429 Points

Can you also show your test code that fails? It seems that you are trying to make a GET request instead of PATCH somehow.

2 Answers

Zachary Fine
Zachary Fine
10,110 Points

This error occurs when you are asking for a route that does not exist. My first instinct would be to check the routes.rb file in the config directory. For better coding practices you should list your routes like this: (It makes it much easier to read and could help fix the problem)

resources :todo_lists do 
    resources :todo_items do 
        member do 
            patch :complete 
            end 
       end 
end

So based on this configuration the route would be todo_list/todo_items/{id}/complete <---- as you can see you are missing the first id. I hope that helps!

Miroslav Králik
Miroslav Králik
7,807 Points

Thank you all!

I overlooked one mistake. In the todo list index.html, I used the patch method not for "Mark Complete" action, but for "Edit". This solved the problem.