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 trial

Ruby Build a Todo List Application with Rails 4 Build a Todo List Application with Rails 4 Viewing Todo Items: Part 2

Brian Patterson
Brian Patterson
19,588 Points

I don't know why I am getting a failure?

Have inputted the code and I am getting this error.


  1) Viewing todo items displays the title of the todo list
     Failure/Error: visit "/todo_list"
       No route matches [GET] "/todo_list"
     # ./spec/features/todo_items/index_spec.rb:7:in `visit_todo_list'
     # ./spec/features/todo_items/index_spec.rb:18:in `block (2 levels) in <top (required)>'

  2) Viewing todo items displays no items when a todo list is empty
     Failure/Error: visit "/todo_list"
       No route matches [GET] "/todo_list"
     # ./spec/features/todo_items/index_spec.rb:7:in `visit_todo_list'
     # ./spec/features/todo_items/index_spec.rb:25:in `block (2 levels) in <top (required)>'

Here is my code

require 'spec_helper'

describe "Viewing todo items" do
  let!(:todo_list) { TodoList.create(title: "Grocery list", description: "Groceries") }

  def visit_todo_list(list)
    visit "/todo_lists"
    within "#todo_list_#{list.id}" do
      click_link "List Items"

  it "displays the title of the todo list" do
    within("h1") do
      expect(page).to have_content(todo_list.title)

  it "displays no items when a todo list is empty" do
    expect(page.all("ul.todo_items li").size).to eq(0)

  it "displays item content when a todo list has items" do
    todo_list.todo_items.create(content: "Milk")
    todo_list.todo_items.create(content: "Eggs")


    expect(page.all("ul.todo_items li").size).to eq(2)

    within "ul.todo_items" do
      expect(page).to have_content("Milk")
      expect(page).to have_content("Eggs")

1 Answer

Run rake routes in the terminal - do you have a route called '/todo_list'?

Post up your routes.rb file, too. And link to your Github repo, if you have one.

Brian Patterson
Brian Patterson
19,588 Points

Here is my bin/rake routes

treehouse:~/projects/odot (master) $ bin/rake routes
                  Prefix Verb   URI Pattern                                             Controller#Action
    todo_list_todo_items GET    /todo_lists/:todo_list_id/todo_items(.:format)          todo_items#index
                         POST   /todo_lists/:todo_list_id/todo_items(.:format)          todo_items#create
 new_todo_list_todo_item GET    /todo_lists/:todo_list_id/todo_items/new(.:format)      todo_items#new
edit_todo_list_todo_item GET    /todo_lists/:todo_list_id/todo_items/:id/edit(.:format) todo_items#edit
     todo_list_todo_item GET    /todo_lists/:todo_list_id/todo_items/:id(.:format)      todo_items#show
                         PATCH  /todo_lists/:todo_list_id/todo_items/:id(.:format)      todo_items#update
                         PUT    /todo_lists/:todo_list_id/todo_items/:id(.:format)      todo_items#update
                         DELETE /todo_lists/:todo_list_id/todo_items/:id(.:format)      todo_items#destroy
              todo_lists GET    /todo_lists(.:format)                                   todo_lists#index
                         POST   /todo_lists(.:format)                                   todo_lists#create
           new_todo_list GET    /todo_lists/new(.:format)                               todo_lists#new
          edit_todo_list GET    /todo_lists/:id/edit(.:format)                          todo_lists#edit
               todo_list GET    /todo_lists/:id(.:format)                               todo_lists#show
                         PATCH  /todo_lists/:id(.:format)                               todo_lists#update
                         PUT    /todo_lists/:id(.:format)                               todo_lists#update
                         DELETE /todo_lists/:id(.:format)                               todo_lists#destroy
                    root GET    /                                                       todo_lists#index
treehouse:~/projects/odot (master *) $ 

And here is my routes.rb file.

Odot::Application.routes.draw do
  resources :todo_lists do
    resources :todo_items
  root 'todo_lists#index'

Don't know how to link to my Github Repo. I have looked in my Github and I don't see the project.