ruby-on-rails - Rails 3 - 如何在 View 中评论?

标签 ruby-on-rails ruby-on-rails-3

Rails 3在 View 中注释一行或多行代码的方法是什么?所以它不会出现在 HTML 源代码中

最佳答案

要注释掉单行 ob ruby​​ 代码,请使用

<%# code %>
or for multiple lines
<%
=begin
 your code
=end
%>

编辑:
这是一个注释掉 View 中循环的示例。
=begin 和 =end 必须直接位于行首。
不能有任何空格或制表符。
<h1>Listing posts</h1>

<table>
  <tr>
    <th>Title</th>
    <th>Text</th>
    <th></th>
    <th></th>
    <th></th>
  </tr>

<%
=begin 
%>
<%@posts.each do |post| %>
  <tr>
    <td><%= post.title %></td>
    <td><%= post.text %></td>
    <td><%= link_to 'Show', post %></td>
    <td><%= link_to 'Edit', edit_post_path(post) %></td>
    <td><%= link_to 'Destroy', post, :confirm => 'Are you sure?', :method => :delete %></td>
  </tr>
<% end %>
<%
=end
%>
</table>

关于ruby-on-rails - Rails 3 - 如何在 View 中评论?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3742453/

相关文章:

ruby-on-rails - 为什么 Date.today - 6.months + 6.months != Date.today?

ruby-on-rails - 计算 ruby​​ 中的可用周数

ruby-on-rails - Rails 最优查询通过 has_many 查找所有文章

ruby-on-rails - 事件管理员搜索状态区域设置不起作用

ruby-on-rails - bcrypt_ext。所以(加载错误)

ruby-on-rails - 我必须在面向服务的系统中购买多少 SSL 证书?

ruby-on-rails - 每个 block 中的 Ruby 动态符号

ruby-on-rails - Rails 3.1 中的未定义方法 `relationships_path'

ruby-on-rails - 我如何将 'join' 数组添加到结果字符串的开头以加入第一个字符?

ruby-on-rails - Ruby on Rails 3,不兼容的字符编码:带有i18n的UTF-8和ASCII-8BIT