首页 > 解决方案 > 在 Ruby on Rails 中创建大型引导表

问题描述

嗨,我对 Ruby on Rails 有点陌生,这应该很简单。我想制作一个大型引导表,同时还能够遍历我的模型/数据库表。

       
      <table class="table">
        <thead>
          <tr>
            <th scope="col">I</th>
            <th scope="col">Id</th>
            <th scope="col">Time</th>
            <th scope="col">Duration</th>
            <th scope="col">Price</th>
            <th scope="col">Name</th>
            <th scope="col">Company</th>
            <th scope="col">City</th>

          </tr>
        </thead>
        <tbody> 
<% 96.times |i| %>
      <% @workorders.each do |workorder| %>
    <tr>
      <td><%= i %></td>
      <td><%= workorder.id %></td>
      <td><%= workorder.time %></td>
      <td><%= workorder.duration %></td>
      <td><%= workorder.price %></td>
      <td><%= workorder.name %></td>
      <td><%= workorder.company %></td>
      <td><%= workorder.city %></td>

    </tr>
    <% end %>
  <% end %>

           
        </tbody>
      </table>

    </div> 

我已经验证,当我只进行一个.each循环时,@workorders它可以正常工作。然而,当我用上面的代码运行我的 Rails 应用程序时,我得到一个语法错误,没有什么太详细的了。创建这个 96 长度的引导表的正确语法是什么,同时还遍历我的模型/sqlite 表?

标签: ruby-on-railsrubyerb

解决方案


杰出的!太感谢了!添加do96.times解决了所有问题。


推荐阅读