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 Cleaning Up Our Code

Jacob Horn
Jacob Horn
9,255 Points

"0 errors prohibited this todo_item from being saved" message is now showing each time I edit a todo item.

I don't believe this was an issue before the render partial: form setup from this video. Here is my code for both files:

edit.html
<h1><%= @todo_list.title %> - Editing Todo List Item </h1>

<%= form_for [@todo_list, @todo_item] do |form| %>

<%= render partial: form %>

<% end %>
_form.html
  <div id="error_explanation">
      <h2><%= pluralize(@todo_item.errors.count, "error") %> prohibited this todo_item from being saved:</h2>

      <ul>
      <% @todo_item.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>


  <%= form.label :content %>
  <%= form.text_field :content %>

  <%= form.submit "Save" %>

Thanks in advance for your help!

1 Answer

Hi Jacob,

I think that there was a mistake when this video was edited after recording. The "error_explanation" div should be wrapped in an if block so that it is only output to the page if there are some errors. In your case it gets output even when there are zero errors which is why you see that message.

If you pause the video at 2:41 you'll see the code that you have but if you pause it again at 3:14 you'll see the additional code. It only shows for 1 second. It must have been added but not shown in the video.

<% if @todo_item.errors.any? %>
  <div id="error_explanation">
    <h2><%= pluralize(@todo_item.errors.count, "error") %> prohibited this todo item from being saved:</h2>

    <ul>
    <% @todo_item.errors.full_messages.each do |message| %>
      <li><%= message %></li>
    <% end %>
    </ul>
  </div>
<% end %>