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

Nelly Lam
Nelly Lam
5,098 Points

Name Error: uninitialized constant

I'm running the tests after editing the controller, and Jason's first test passed, but both of mine are failing. I've already triple checked all the code and I believe it's identical. I can't seem to find where my mistake is.

This is the error I'm getting: Failures:

1) Viewing todo items displays the title of the todo list Failure/Error: click_link "List Items" NameError: uninitialized constant TodoItemsController::Todolist # ./app/controllers/todo_items_controller.rb:3:in index' # ./spec/features/todo_items/index_spec.rb:9:inblock (3 levels) in <top (required)>' # ./spec/features/todo_items/index_spec.rb:8:in `block (2 levels) in <top (required)>'

2) Viewing todo items displays no items when a todo list is empty Failure/Error: click_link "List Items" NameError: uninitialized constant TodoItemsController::Todolist # ./app/controllers/todo_items_controller.rb:3:in index' # ./spec/features/todo_items/index_spec.rb:9:inblock (3 levels) in <top (required)>' # ./spec/features/todo_items/index_spec.rb:8:in `block (2 levels) in <top (required)>'

My todo_items_controller.rb looks like this:

class TodoItemsController < ApplicationController
  def index
    @todo_list = Todolist.find(params[:todo_list_id])
  end
end

My todo_items index.html.erb:

<h1><%= @todo_list.title %></h1>
<p>Find me in app/views/todo_items/index.html.erb</p>

And my index_spec.rb:

require 'spec_helper'

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

    before do
        visit "/todo_lists"
        within "#todo_list_#{todo_list.id}" do
            click_link "List Items"
        end
    end


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

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

Please help!

1 Answer

Nelly Lam
Nelly Lam
5,098 Points

Just found the error. In the controller, it should be TodoList not Todolist. The 'L' needs to be capitalized.

I really wish this tutorial would go a little slower and explain what is going on...

Jason Seifer
Jason Seifer
Treehouse Guest Teacher

Great work, Nelly Lam! I'll go a little slower in future lessons.