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

sihaiyunyou · December 01, 2011 · Last by wmzsonic replied at March 23, 2017 · 5296 hits
<%%= 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 的模板文件的,比如生成器使用的模板

You need to Sign in before reply, if you don't have an account, please Sign up first.