Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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>
      </tr>
<% end %>

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

<tbody>
      <tr id="todo_list_3">
        <td>Grocerries</td>
        <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>
      <tr id="todo_list_4">
        <td>Work</td>
        <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>
      </tr>
  </tbody>

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?