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/