Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMiroslav Králik
8,448 PointsNo 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
2 Answers
Zachary Fine
10,110 PointsThis 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
8,448 PointsThank 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.
Angel Israel Gallegos Espinoza
3,096 PointsIt works for me, thanks!!!
Maciej Czuchnowski
36,441 PointsMaciej Czuchnowski
36,441 PointsCan you also show your test code that fails? It seems that you are trying to make a GET request instead of PATCH somehow.