0

I'm using Rails to display a set of data. The problem is that data is so large I dont really do the usually for each loop since I creates this insanely long list.

My solution would be to create some form of table where after 10 records create a new cell and after 5 cells create a new row. I'm not really that comfortable with for loops in rails so I figured throw the question out.

Right now I have...

<strong> Person Data Set: </strong><br />
<% for person in @persons %>
   <%= interest.name %> <br />
<% end %>

So I can I create a loop similar to this?

  <strong> Person Data Set: </strong><br />
  <table>
  <tr>
  *****for each 5 cells???? *****
  <td>
  *****For each 10 records?? ***
  </td>
  </tr>
  </table>

Has anyone had to deal with an issue like this before?

1 Answer 1

3

There is an each_slice method. With HAML (I really don't like ERB but the idea is the same):

%strong
  Person Data Set:
%br
%table
  - @persons.each_slice(10) do |ten_people| 
    %tr
      - ten_people.each_slice(5) do |five_people|
        %td
          - five_people.each do |person|
            %p= person.name 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.