循环视图的导轨

Bla*_*543 6 ruby-on-rails-3

我有以下代码:

<tbody>
   <%= Item.each do |item|=%>
   <tr>
      <th><%= item.rev =%></th>      <=========
      <th><%= item.name =%></th>
   </tr>
   <%= end =%>
</tbody>
Run Code Online (Sandbox Code Playgroud)

但是,我在inidcated行上收到语法错误.数据库中有数据(测试用例).不知道我做错了什么.

小智 14

等于你有的迹象是错误的.请尝试以下方式:

<tbody>
   <% Item.each do |item|%>
   <tr>
      <th><%= item.rev %></th>     
      <th><%= item.name %></th>
   </tr>
   <% end %>
</tbody>
Run Code Online (Sandbox Code Playgroud)

<%=应仅用于需要评估的表达式.

要了解嵌入式ruby,请参阅此链接 http://www.ruby-doc.org/docs/ProgrammingRuby/html/web.html