[英]What is the meaning of <%%= in Ruby on Rails?
除了在我正在合作的项目中,我在任何地方都找不到它。 它不能以与<%=
(我尝试更改)相同的方式工作,但是我无法理解其中的区别。
<span class="option-content" placeholder="<%=t('pages.edit.option')%>">
<%%= content %>
</span>
这里的ERB码头说
<% Ruby code -- inline with output %>
<%= Ruby expression -- replace with result %>
<%# comment -- ignored -- useful in testing %>
% a line of Ruby code -- treated as <% line %> (optional -- see ERB.new)
%% replaced with % if first thing on a line and % processing is used
<%% or %%> -- replace with <% or %> respectively
这意味着
<%%= content %>
将被替换为
<%= value of content %>
简而言之, ERb将双百分号标记转换为单百分号标记。
看来您正在使用一层ERb模板来生成另一层ERb模板。
ERb的第一层不需要名为content
的变量,只需使用t
方法:
<span class="option-content" placeholder="<%=t('pages.edit.option')%>">
<%%= content %>
</span>
渲染第一层以生成第二层:
<span class="option-content" placeholder="Edit">
<%= content %>
</span>
如您所见,这也是一个ERb模板。 我希望以后再有其他东西可以使用第二个ERb并使用它来呈现类似以下内容的东西:
<span class="option-content" placeholder="Edit">
Hello, world.
</span>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.