【发布时间】: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