Rails For 循环视图 [英] Rails For Loop View

查看:27
本文介绍了Rails For 循环视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

<tbody>
   <%= Item.each do |item|=%>
   <tr>
      <th><%= item.rev =%></th>      <=========
      <th><%= item.name =%></th>
   </tr>
   <%= end =%>
</tbody>

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

However I am getting a syntax error on the inidcated line. There is data in the database(Test case). No idea what I am doing wrong.

推荐答案

你所拥有的等号是错误的.尝试如下:

The equals to signs you have are wrong. Try as below:

<tbody>
   <% Item.each do |item|%>
   <tr>
      <th><%= item.rev %></th>     
      <th><%= item.name %></th>
   </tr>
   <% end %>
</tbody>

<%= 应该只用于需要计算的表达式.

The <%= should only be used for expressions that need to be evaluated.

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

To help understand embedded ruby see this link http://www.ruby-doc.org/docs/ProgrammingRuby/html/web.html

这篇关于Rails For 循环视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆