Rails如何转义和显示渲染视图的内容

Rya*_*yan 3 html ruby views ruby-on-rails ruby-on-rails-3

我试图在textarea中显示rails视图文件.视图文件包含一堆HTML,我想要转义它,以便它不会干扰页面html.这是一个例子:

In this view we are going to display the contents of a partial
<textarea>
<%= html_escape render('partial') %>
</textarea>
Run Code Online (Sandbox Code Playgroud)

在partial.html.erb我会

Hello this is partial.html.erb and this is a 
<textarea>textarea</textarea>  blah blah blah.
Run Code Online (Sandbox Code Playgroud)

问题是:partial.html中的textarea在第一个视图中打破了textarea,因为它不是html_escaped.如何在属性中转义并显示textarea内部分的内容?

Max*_*lze 5

你尝试过使用过吗?

<%= CGI.escapeHTML render('partial') %>
Run Code Online (Sandbox Code Playgroud)