2016-11-08 10 views
2

私は協力しているプロジェクトのどこにでもそれを見つけることができません。 <%=(私は変更しようとしました)と同じように動作しませんが、違いは分かりません。Ruby on Railsで<%% =の意味は何ですか?

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

は、あなたが完全な表現を提供することができます:私は何か他のものが、後に、第二のERbことを取り、のようなものをレンダリングするためにそれを使用することを期待しますか? – Aleksey

+0

これで十分ですか? – Simoroshka

+2

あなたはそれがタイプミスではないと確信していますか?それが1つだけの場合は何の出力を与えますか? – mjwatts

答えて

1

で置換されるであろう

<%%= content %> 
の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 

言うドッキング二重パーセント記号を一重記号に変換する。


あなたがのERBテンプレートの別の層を生成するのERBテンプレートの一つの層を使用しているように見えます。

のERbの第一層はcontentという変数だけt方法は必要ありません:

<span class="option-content" placeholder="Edit"> 
    <%= content %> 
</span> 

:第1の層が第二の層を生成するためにレンダリングされていることを

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

をご覧のとおり、これもERbテンプレートです。

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

代わりにこの回答を受け入れるつもりです。ありがとうございます。 – Simoroshka

3

ERB hereこれは

は要するに

<%= value of content %> 
+0

に<%= content%>を作成するので、 '<%% ='の代わりに '<% '? – mjwatts

+1

「<%% content %%>」は「<%content%>」に置き換えられ、「<%% content %%>」は「<%=コンテンツの%」>に置き換えられます。 –

+0

ありがとう、それは少し物事を明確にした! (私はまだそれがこのプロジェクトのような理由は分かっていますが、別の質問です) – Simoroshka

関連する問題