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

Viewing todo items part 1

I'm getting the following error code in the last test

1) Viewing todo items displays no items when the todo list is empty Failure/Error: click_link "List Items" Capybara::Ambiguous: Ambiguous match, found 2 elements matching link "List Items" # ./spec/features/todo_items/index_spec.rb:8:in block (3 levels) in <top (required)>' # ./spec/features/todo_items/index_spec.rb:7:inblock (2 levels) in <top (required)>'

My code in index_spec.rb is exactly what it should be (same as the video) so i don't know where to look for the error. Can anyone help?

Thanks Rob

12 Answers

Remove:

<a href="">List Items</a>

Ted, you're a lifesaver! Thank you for working through this failure to find the correct solution. I was getting ready to lose my head.

Just to add, my code in index_spec is

require 'spec_helper'

describe "Viewing todo items" do let!(:todo_list) { TodoList.create(title: "Grocery List", description: "Groceries")} it "displays no items when the todo list is empty" do visit "/todo_lists" within "#todo_list_#{todo_list.id}" do click_link "List Items" end expect(page).to have_content("TodoItems#index") end end

Can't see anything wrong in there, but maybe i'm missing something?

Rob

Paste your index.html.erb code in here. I just did this video series and everything works.

Actually if I remember right this error is expected because there are going to be many "List Items" on the page (one for each Todo List.)

You have to use a within block (which Jason does explain) using the dom_id for the todo_list.

Hi Brandon, I didn't amend anything in there. It's still

<h1>TodoItems#index</h1> <p>Find me in app/views/todo_items/index.html.erb</p>

Did i doze through a bit of the video? :/

I used within "#todo_list_#{todo_list.id}"

That should be

#todo_list_#{todo_list.id}

Apologies, my mistake. That's what i have in the code, I just retyped it wrong (note to self: copy and paste).

"#todo_list_#{todo_list.id}" is what i'm using but it is still giving me the ambiguity error

Still wrong, you're missing one underscore:

You have this in your code from your index_spec.rb:

within "#todo_list#{todo_list.id}" do 
    click_link "List Items" 
end 

It should be this:

within "#todo_list_#{todo_list.id}" do 
    click_link "List Items" 
end 

Notice the missing underscore before the second hashtag.

I don't know why it's missing out the underscores but i am typing them and they are in my code. One between todo and list, one between list and # and one between click and link. For some reason they're removed when i hit post answer but they are there exactly as you've said in your response

Ok, then i recommend going over the video again. Somewhere something is mistyped. It seems that the within block is not working correctly.

I would check the todo_list index.html.erb page because it seems that it's not recognizing the dom_id there.

Ok thanks for your help Brandon, I'll try the video again

I encountered the same issue. The fix was to remove the following line of code from the 'index.html.erb - todo_lists' file: <a href="">List Items</a>

Remove: <a href="">List Items</a>