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

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -