在Rails 3.2.11中的label_tag中渲染html(html_safe,raw not working)

Chr*_*fer 6 label ruby-on-rails

使用:Rails 3.2.11和Ruby 1.8.7

我在尝试label_tag输出html 时遇到了一些严重的问题.基本上它归结为:

<%= label_tag "This will <strong>not</strong> work!" %>
Run Code Online (Sandbox Code Playgroud)

我试过了:

<%= raw label_tag "This will <strong>not</strong> work!" %>
<%= label_tag raw "This will <strong>not</strong> work!" %>
<%= label_tag "This will <strong>not</strong> work!".html_safe %>
<%= (label_tag "This will <strong>not</strong> work!").html_safe %>
Run Code Online (Sandbox Code Playgroud)

我已经安装了gem'trail_xss'.

什么都行不通!

虽然我可以通过转义html找到很多相关的问题,其中人们遇到raw和html_safe问题,但是与label_tag无关.我无法使用f.label来解决这个问题.

这曾经用于相同的应用程序,但经过一些更新(其中Rails 3.0.3 - > 3.2.11是主要的)它停止工作.我没有注意到这发生的时间,所以我不确定是什么原因引起了这个问题.

你能复制一下吗?你有解决方案吗?

mch*_*ail 8

问题是第一个参数label_tag应该是标签名称.如果要在标记内显示自定义内容,则必须是第二个参数.

http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-label_tag

试试这个:

<%= label_tag "my label name", raw("This will <strong>not</strong> work!") %>
Run Code Online (Sandbox Code Playgroud)