如何在rails 3.1中的水平表中显示条目 [英] How can I display entries in a horizontal table in rails 3.1
问题描述
我想在Rails中显示电子商务页面的项目,而不是标准的垂直列表,我想从左到右,大约4的标题和图像,然后继续列表添加:ie
条目1条目2条目3条目4
条目5条目6 ....
我的第一个猜测是为每个列创建一个作用域,其中我可以跳过4个因子,但我想知道是否有更好的解决方案使用CSS或任何其他技巧?
Enumerable上有一个方法,名为 each_slice
。基本上它所做的是给你一个数组。
(1..10).each_slice(3){| a | pa}
#输出低于
[1,2,3]
[4,5,6]
[7,8,9]
[10]
使用CSS的另一个选择是使用固定宽度的容器,例如400px,元素有 width:100px
和 float:left
,所以他们会一个接一个。 >
I would like to display items for an e-commerce page in Rails, and instead of a standard vertical list table, I would like to the title and images from left to right, about 4 across, then continue the list on as added: ie.
Entry 1 Entry 2 Entry 3 Entry 4
Entry 5 Entry 6 ....
My first guess is to make a scope for each column- where I could skip entries by a factor of 4, but I would like to know if there is a better solution using CSS or any other trick?
There's a method on Enumerable which is called each_slice
. Basically what it does is give you slices of an array.
(1..10).each_slice(3) {|a| p a}
# outputs below
[1, 2, 3]
[4, 5, 6]
[7, 8, 9]
[10]
Another option using CSS would be to have a container of fixed width, say 400px, and then have each of the elements have width: 100px
and float: left
, so they'll line up one after another.
这篇关于如何在rails 3.1中的水平表中显示条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!