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 Adding Validations to Todo Items

I need help to figure out how to resolve this error.

1) Adding todo items is successful with valid content Failure/Error: click_link "New Todo Item" ActionView::Template::Error: First argument in form cannot contain nil or be empty # ./app/views/todo_items/new.html.erb:1:in _app_views_todo_items_new_html_erb__984293410__579391758' # ./spec/features/todo_items/create_spec.rb:16:inblock (2 levels) in <top (required)>'

5 Answers

Hi, Nicolas Nahimana

Review the code inside your controller to make sure you're defining and referring to the same variables inside your views.

Please provide your code wrapped around 3 grave characters before and after the code snippet to allow me and the rest of the Treehouse community be in a better position to help you more.

Hi Kevin, thanks for the assistance. I am going to review the code and I will inform you of my progress.

Gameli Ladzekpo
Gameli Ladzekpo
5,324 Points

Hey Kevin, I'm finding the same error

This is my controller

'''

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

def new @todo_list = TodoList.find(params[:todo_list_id]) @todo_list = @todo_list.todo_items.new end

def create @todo_list = TodoList.find(params[:todo_list_id]) @todo_list = @todo_list.todo_items.new(todo_item_params) if @todo_item.save flash[:success] = "Added todo list item." redirect_to todo_list_todo_items_path else flash[:error] = "There was a problem adding that todo list item" render action: :new end

end

private def todo_item_params params[:todo_item].permit(:content) end

end (''')

This is my view

'''ruby <%= form_for [@todo_list, @todo_item] do |form| %> <%= form.label :content %> <%= form.text_field :content %>

<%= form.submit "Save" %>

<% end %>

'''

This is my spec

'''ruby require 'spec_helper'

describe "Adding 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 "is successful with valid content" do
    visit_todo_list(todo_list)
    click_link "New Todo Item"
    fill_in "Content", with: "Milk"
    click_button "Save"
    expect(page).to have_content("Added todo list item.")
    within("ul.todo_items") do
        expect(page).to have_content("Milk")
end

end

end

'''

Would really appreciate a point in the right direction.

Gameli Ladzekpo
Gameli Ladzekpo
5,324 Points

Okay - solved it my issue, Kevin you were right. i didn't actually declare a variable called @todo_item, i declared @todo_list twice by accident.

Gameli Ladzekpo: Okay, awesome; good luck with the rest of the course!