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!

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 Editing Todo Lists

Kenan Xin
Kenan Xin
16,139 Points

Different tr id in html ? Why?

The dom_id(todo_list) is supposed to bind tr id with row ids in database, the first row = 1, second row = 2 etc

<% @todo_lists.each do |todo_list| %>
      <tr id = "<%= dom_id(todo_list) %>">
        <td><%= todo_list.title %></td>
        <td><%= todo_list.description %></td>
        <td><%= link_to 'Show', todo_list %></td>
        <td><%= link_to 'Edit', edit_todo_list_path(todo_list) %></td>
        <td><%= link_to 'Destroy', todo_list, method: :delete, data: { confirm: 'Are you sure?' } %></td>
<% end %>

However, when i inspect the html, the actual codes are :

      <tr id="todo_list_3">
        <td>My grocery list</td>
        <td><a href="/todo_lists/3">Show</a></td>
        <td><a href="/todo_lists/3/edit">Edit</a></td>
        <td><a data-confirm="Are you sure?" rel="nofollow" data-method="delete" href="/todo_lists/3">Destroy</a></td>
      <tr id="todo_list_4">
        <td>Work to do</td>
        <td><a href="/todo_lists/4">Show</a></td>
        <td><a href="/todo_lists/4/edit">Edit</a></td>
        <td><a data-confirm="Are you sure?" rel="nofollow" data-method="delete" href="/todo_lists/4">Destroy</a></td>

As you can see, the number starts from 3, instead of 1 , or 2, could anyone explain to me why?

1 Answer

One answer here to the best of my knowledge, every time you create a todo it gets it's own id. Even if you delete a previous todo, the id's continue to go up (3, 4). Did you delete some previously created todos?