How can I display entries in a horizontal table in rails 3.1

我的未来我决定 提交于 2019-12-06 09:35:53

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/8548309/how-can-i-display-entries-in-a-horizontal-table-in-rails-3-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!