Place an iterator in a table in a .pdf.erb file

Asked

Viewed 38 times

1

I have a table where there is a list of people wanted to put a counter to stand a number next to each item on the list:

kind of:

1-Maria.

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>

1 answer

1


Just use the method #each_with_index in place of #each to make the iteration.

<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>
  • 1

    opa young obg worked out! Thanks!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.