2016-11-08 48 views
2

我无法在任何地方找到它,但在我正在使用的项目中。 它不能像<%=(我试图改变)那样工作,但我无法理解它们之间的区别。<%% =在Ruby on Rails中的含义是什么?

<span class="option-content" placeholder="<%=t('pages.edit.option')%>"> 
    <%%= content %> 
</span> 
+1

可以提供完整的表达? – Aleksey

+0

这够了吗? – Simoroshka

+2

你确定它不是一个错字 - 如果它只有一个,它会给出什么样的输出。% – mjwatts

回答

1

总之代替,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模板。我想到的是别的东西,后来,采取的是第二该局及使用它来呈现类似:

<span class="option-content" placeholder="Edit"> 
    Hello, world. 
</span> 
+0

我会接受这个答案,而不是,谢谢。 – Simoroshka

3

该ERB停靠here

<% 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 %> 
+0

中创建<%= content%>,所以不是'<%% ='实际上应该是'<%%'生成'<% '? – mjwatts

+1

将<%% content %%>'替换为<%value of content%>',<%% = content %%>'将替换为<%= value of content%>' –

+0

谢谢,它澄清了一些事情! (我仍然需要明白为什么它是这样的项目,但它是一个不同的问题) – Simoroshka