I have an object called @events containing about 50 records being pulled from a find condition of my model.
I’m currently displaying the results of the @object in my view like this….
<% for event in @events %>
<p><%= @event.name %></p>
<% end %>
Instead of displaying the entire 50 I would like shrink the set to about 10 records so it displays better on the page.
I cannot use :limit in the find condition since the object is being composed from a variety of loops where after each iteration it adds a few specific records.
So the issue is I have this object @events with 50 records, how can I change the object after its been composed so only the first 10 records remain?
First of all, if you’d like to have pagination, I strongly suggest taking a look at will_paginate
Alternatively, you can do the following to read the first 10 records only.
Or the last 10 records
I didn’t test it but you get the point.