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 trialRob Williams
18,708 PointsCan't get past 'Unable to find field: content'
Is anyone else having this problem? I've been back through the video and checked my code but I just can't put a dent in that error. Is it a rails version thing? It all works fine when I just open the app and go through creating and editing a todo item myself, just not in this test
4 Answers
Steve Hunter
57,712 PointsIt is a while since I've done this course and I found it a huge struggle, I have to say.
I'm looking through my code and it is very different to yours but that's easily explained as I got almost to the end of the course before giving up on it completely!
Your test is taking a few steps - it is visiting the todo list, clicking on edit and is then attempting to complete a field called :content
with a string. That's where it is struggling - it can't find a field called content
. In my app there seems to be a couple of fields, :title
and :description
.
Anyway, here's my test:
it "is successful with valid content" do
visit_todo_list(todo_list)
within("#todo_item_#{todo_item.id}") do
click_link "Edit"
end
fill_in "Content", with: "Lots of milk"
click_button "Save"
expect(page).to have_content("Saved todo list item")
todo_item.reload
expect(todo_item.content).to eq("Lots of milk")
end
So, change your :content
to "Content"
, perhaps?
Steve
Steve Hunter
57,712 PointsHi Rob,
Which test is it, and what does your test & code look like?
Steve.
Rob Williams
18,708 PointsWell, three different tests come up with that same error so I'm having trouble nailing down where the problem is. Jason fixes things without fixing that for a couple of minutes and somewhere in there I've missed something. I'm not sure what code to paste here but I think I've added:
def edit
@todo_list = TodoList.find(params[:todo_list_id])
@todo_item = @todo_list.todo_items.find(params[:id])
end
def url_options
{todo_list_id: params[:todo_list_id]}.merge(super)
end
it "is successful with valid content" do
visit_todo_list(todo_list)
within("#todo_item_#{todo_item.id}") do
click_link "Edit"
end
fill_in :content, with: "Lots of Milk"
click_button "Save"
expect(page).to have_content("Saved todo list item")
todo_item.reload
expect(todo_item.content).to eq("Lots of Milk")
end
and copied the new form over to the edit.html.erb file
Thanks,
Rob
Rob Williams
18,708 PointsBloody 'ell, that was it exactly. Thank you.
One little thing and it all flies out the window. Man I love/hate coding
Steve Hunter
57,712 PointsYeah - it is a bit like that at time!
The Ruby on Rails course can be quite tricky as you progress through it so don't struggle alone - keep asking questions when you get stuck. I hope you don't get stuck, obviously! :-)
Steve.