RoR 3 - f.label 嵌入一个标签 - 方法
我将如何执行以下操作。
我当前的代码是:
<%= f.label :email, html_escape("<span class=\"big\">Test</span>") %>
这没有显示我想要的内容,因为它
<span class=\"big\">Test</span>
显示为文本而不是 HTML。
我一直在考虑覆盖 FormBuilder,但我不知道如何做到这一点,并且搜索类似的东西并没有解决我的问题。
另外,我想显示变量:电子邮件,而不是测试。
我只是想解决我遇到的问题:)
PS。我正在使用 Rails 3.0。
How would i do the following.
My current code is :
<%= f.label :email, html_escape("<span class=\"big\">Test</span>") %>
This doesn't shows what i want, because the
<span class=\"big\">Test</span>
is shown as text instead of HTML.
I have been thinking of overriding the FormBuilder, but i don't know how i would do this and searching for something similar hasn't solved my problems.
Also, instead of Test i want to show the variabel: email.
I just want to solve the problem that i have :)
PS. I'm using Rails 3.0.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Rails 3 中的所有助手都是 html_escape,因此不再需要它。
不要使用 html_escape 它工作正常。您需要使用 raw
或者您可以将此链标记为安全
All helper in rails 3 are html_escape, so it's not anymore needed.
don't use html_escape and it's works fine. You need use raw
Or you can mark this chain as safe
您正在
html_escape
'ing 跨度...这就是跨度 html 显示在您的页面上的原因。如果你去掉它,它只会呈现为 html,这就是你想要的。You are
html_escape
'ing the span...that is why the span html is showing up on your page. If you get rid of that, it'll just render as html, which is what you want.