Rails:如何以行而不是一列显示图像

yos*_*osh 1 css ruby-on-rails view

目前,我的代码生成的视图如下所示:

Lessons Start Now!
x
x
x
x
x
x
Run Code Online (Sandbox Code Playgroud)

(其中x =图片)

我想知道如何使其显示如下:

Lessons Start Now!
x   x   x
x   x   x
Run Code Online (Sandbox Code Playgroud)

这是我的index.html.erb代码

<h1>Lessons Start Now!</h1>
<% @lessons.each do |lesson| %>
    <%= image_tag(lesson.image, :size => "100x50") %><br />
    <%= lesson.subject %><br />
<% end %>
<%= link_to 'New Lesson', new_lesson_path %>
Run Code Online (Sandbox Code Playgroud)

我唯一能想到的就是编写一个有计数的for循环。它将把第一个图像插入一个div类,然后一旦count = 3,它将把接下来的3个图像插入另一个div。也许可以使用ul和li进行一些特殊的操作,或者有一个方法,任何帮助将不胜感激。

fl0*_*00r 5

您可以做一个表格(或浮动div)

<table>
  <% @lessons.each_slice(3) do |lessons| %>
    <tr>
      <% lessons.each do |lesson| %>
        <td>
          <%= image_tag(lesson.image, :size => "100x50") %><br />
          <%= lesson.subject %>
        </td>
      <% end %>
    </tr>
  <% end %>
</table>
Run Code Online (Sandbox Code Playgroud)