简体   繁体   English

如何仅使用部分创建4x4网格?

[英]How do I create a 4x4 grid with partials only?

Say I have 16 objects in my collection, I want to create 4 rows of 4 each. 假设我的集合中有16个对象,我想创建4行,每行4个。

How do I do that using partials? 我如何使用partials?

One way is to just use one partial on the main page, and have that partial render each row. 一种方法是在主页面上使用一个部分,并使该部分呈现每一行。 Then inside that partial, have it 4 objects - but how do I actually do that such that it doesn't repeat objects and all this good stuff? 然后在那部分内部,有4个对象 - 但我怎么做到这一点,它不重复对象和所有这些好东西?

So the structure I am thinking is a partial (that produces 4 rows) and in each partial is another partial that produces 4 objects side by side. 所以我想的结构是局部的(产生4行),而每个部分是另一个并排产生4个物体的部分。

But not quite sure how to pull that off. 但不太确定如何解决这个问题。

Suggestions? 建议?

<% @objects.in_groups_of(4, false) do |objects| %>
  <div class="row">
    <% objects.each do |object| %>
      <%= render object %>
    <% end %>
  </div>
<% end %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM