I am using Ruby (+ Sinatra) to work on one of my web projects.
I have an array with quite a bit of content and only want to display 10 of the array elements per page.
So what I did so far is:
-
creating an array with all of the content
ary = ["ex1", "ex2", "ex3", … ,"ex60" ] // all elements -
splitting the array into subarrays
ary.each_slice(10).to_a // subarrays with fewer content
Now, I need a way to split the subarrays into single arrays and give them a name,
for example:
@subAry1 # ex1, ex2, ex3, … ex10
@subAry2 # ex11, ex12, ex13, … ex20
@subAry3 # ex21, ex22, ex23, … ex30
I stuck on creating these arrays with a continuing number in the array name.
When I would have my arrays split, I would use this in my .erb file:
<% currentAry = @subAry1 %>
<% currentAry.each do |element| %><%= element %><% end %>
and this to change the content, if the “next” button gets pressed:
currentAry = @subAry + '1'
Can somebody help me, or is it even an effective way, to split/display array elments on my page?
How about an array of arrays? Here’s something to help you get started.
In the ERB file:
and after the “next” button gets pressed