Placing an iterator on a table in a .pdf file.erb

1

I have a table where there is a list of people I want to put a counter to get a number on the side of each item in the list:

type like this:

1-Mary.

Segue arquivo financial.pdf.erb''<tbody>
        <% @people[:people].each do |person| %>
            <tr>
                <td> <%= person.name %></td>
                <td> <%= person.created_at.strftime('%d/%m/%Y') %></td>
                <td> <%= person.delete_date.strftime('%d/%m/%Y') unless person.delete_date.nil? %></td>
                <td> <%= person.type_desc %></td>
            </tr>
        <% end %>
    </tbody>

have an example in html:

                                <tr ng-repeat="person in people">
                                    <td>{{$index + 1}} - {{person.name}}</td>
                                    <td>{{person.created_at.formatDate()}}</td>
                                    <td>{{person.delete_date.formatDate()}}</td>
                                    <td>{{person.type_desc}}</td>
                                </tr>
                            </tbody>
                        </table>
    
asked by anonymous 12.04.2016 / 18:58

1 answer

1

Just use the #each_with_index method instead of #each to iterate.

<tbody>
    <% @people[:people].each_with_index do |person, index| %>
        <tr>
            <td><%= index + 1 %> - <%= person.name %></td>
            <td> <%= person.created_at.strftime('%d/%m/%Y') %></td>
            <td> <%= person.delete_date.strftime('%d/%m/%Y') unless person.delete_date.nil? %></td>
            <td> <%= person.type_desc %></td>
        </tr>
    <% end %>
</tbody>
    
06.05.2016 / 16:33