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!

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.

Failures:

  1) Viewing todo items displays the title of the todo list
     Failure/Error: visit "/todo_list"
     ActionController::RoutingError:
       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"
     ActionController::RoutingError:
       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"
    end
  end

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

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

  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")

    visit_todo_list(todo_list)

    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")
    end
  end
end

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
  end
  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.