【问题标题】:Creating large bootstrap table in Ruby on Rails在 Ruby on Rails 中创建大型引导表
【发布时间】:2021-09-20 11:47:21
【问题描述】:

您好,我对 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> 

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

【问题讨论】:

  • 如果应该是96.times do |i|,我猜这是你的“没什么太详细的”错误信息。让我知道这是否解决了问题
  • ruby 语法是 10.times {|i| }10.times do |i| end 但没有 10.times |i| 因为它缺少块打开语句。

标签: ruby-on-rails ruby erb


【解决方案1】:

太棒了!太感谢了!在96.times 之后添加do 解决了所有问题。

【讨论】:

  • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 2013-04-29
  • 2011-02-05
  • 1970-01-01
  • 2014-02-16
  • 2012-11-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-01
相关资源
最近更新 更多