Ruby each do loop 'n' number of times -
hi i'm having trouble below loop in .erb view
<% my_list.each | list | %> .. loop stuff..... <% end %.
this works fine looping through list, want loop through first 4 items in 'my_list' , not whole list. tried things like:
<% my_list.each | product | 3.times %>
but didn't seem work think ruby knowledge limited least!
take first 4 element my_list
array#first:
<% my_list.first(4).each | product | %>
use array#each_slice slice array
<% my_list.each_slice(4) | products | %> <% products.each | product | %>
Comments
Post a Comment