Answer the question
In order to leave comments, you need to log in
How to display a sorted array by columns in a view?
Good day!
There is an array sorted by some data, let's call it @array . It has, for example, 47 elements. You need to display the contents of the array in the view by columns, not by rows using bootstrap. If output like this:
- @array.each do |x|
.col-sm-3.col-md-3.col-lg-3
= x
/ Desktop list.
.hidden-xs.text-center
- @array.in_groups(4, false).each do |array|
.col-sm-3.col-md-3.col-lg-3
- array.each do |value|
.row
= link_to value[:name], make_path(value[:id])
/ Mobile list.
.visible-xs.text-center
- @array.in_groups(2, false).each do |array|
.col-xs-6
- array.each do |value|
.row
= link_to value[:name], make_path(value[:id])
Answer the question
In order to leave comments, you need to log in
there is no way you can do it like this,
you need to write crutches, for example,
measure the number of array elements,
divide this number by 4 and write down the conditions for displaying elements
@array.in_groups_of((@array.size.to_f/2).ceil, false) do |array|
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question