Rails 模板文件里面一个百分号和两个百分号的区别

sihaiyunyou · 2011年12月01日 · 最后由 wmzsonic 回复于 2017年03月23日 · 5294 次阅读
<%%= content_for :base_sitemap do %>
<a href="<%%= <%= plural_table_name %>_path %>"><%= plural_table_name %></a> » 
<%% end %>
<%%= content_for :styles do %>
<%% end %>

<%%= spaceless do %>
<div class="tools">
  <a href="<%%= <%= plural_table_name %>_path %>" class="button small left<%%= ' checked' if params[:action] == "index" %>">查看所有</a>
  <%% if ["edit","update"].index(params[:action]) %>
  <a href="#" class="button small checked">编辑</a>
  <%% end %>
  <a href="<%%= new_<%= singular_table_name %>_path %>" class="button small right<%%= ' checked' if ["new","create"].index(params[:action]) %>">新建</a>
</div>
<%% end %>

这是者也里面的一个_base.html.erb 文件的代码,里面出现了很多<%% ... %>这样的代码,而其他的_base.html.erb 都是以一个百分号开头的,请问这两个百分号和一个百分号的区别是什么?

同问, @huacnlee 来给我们解释一下吧。

我也没见过~

估计纯粹 geek 的写法吧 , 应该没区别

我也遇到了,好像是 2 个%(<%%=模板生成的文件会保留<% %> 一个%(<%= 不保留

没看过 另外百分号真的超级丑......宁愿 php 那样的<? ?>

主要是用于生成 erb 的模板文件的,比如生成器使用的模板

需要 登录 后方可回复, 如果你还没有账号请 注册新账号