将<%作为.erb文件中的文字

时间:2015-03-10 21:11:37

标签: ruby-on-rails ruby erb

假设我想在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

愚蠢的问题,是吗?我该怎么做?

谢谢!

2 个答案:

答案 0 :(得分:2)

你可以把它写成:

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;

答案 1 :(得分:1)

尝试使用实体:

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