【问题标题】:Put <% as a literal in an .erb file将 <% 作为文字放在 .erb 文件中
【发布时间】:2015-05-12 12:10:09
【问题描述】:

假设我想在 erb 页面中显示如何编写 erb 的提示:

在 helpfile.html.erb 中:

Here's the right way to write a basic erb statement: <%= a = 1 %>

问题在于,当该 erb 文件在 rails 中作为视图处理时,文字 erb &lt;%= 被解释,因此在显示的文件中我只看到了

Here's the right way to write a basic erb statement: 1

我该怎么做?

【问题讨论】:

标签: ruby-on-rails ruby erb


【解决方案1】:

你可以这样写:

Here's the right way to write a basic erb statement: <%= '<%= a = 1 %>' %>

或者也许是:

Here's the right way to write a basic erb statement: &lt;%= a = 1 %&gt;

【讨论】:

    【解决方案2】:

    尝试使用实体:

    <&#37;= Here's the right way to write a basic erb statement: 1 &#37;>
    

    【讨论】:

    • 不喜欢&amp;lt;&amp;gt; 对于我们这些没有记住ASCII 表的人?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-26
    • 2014-07-10
    • 1970-01-01
    • 2015-08-22
    • 2022-12-22
    • 1970-01-01
    相关资源
    最近更新 更多