Rails 3 视图中的 Html 转义
我正在使用 Rails 3。我想在 erb 模板
<%= "<div>Foo Bar</div>" %>
Rails 编码 div 标签内显示生成的 html 片段。
如果我在 Rails 2 中是正确的 <%=h
会导致 html 转义。似乎Rails 3中已更改。如何在Rails 3中插入不编码的html片段?
问候, 阿列克谢.
I'm using Rails 3. I want to display generated html fragment inside erb template
<%= "<div>Foo Bar</div>" %>
Rails encodes div tags.
If I'm correct in Rails 2 <%=h
causes html escaping. Seems that it was changed in Rails 3. How can insert html fragment without encoding in Rails 3?
Regards,
Alexey.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设编码指的是 html 转义:
要在 Rails 3 中输出原始 html,您可以使用三种不同的方法。
您可以使用
raw
帮助器输出原始html更多信息:ActionView::Helpers::OutputSafetyHelper #raw
您可以将字符串标记为
html_safe
更多信息:String#html_safe 和 ActiveSupport::SafeBuffer#new
sanitize
清理输出更多信息:ActionView::Helpers::SanitizeHelper #sanitze
更多信息:
I assume by encoding you mean the html-escaping:
To put out raw html in Rails 3 you can use three different approaches.
your can use the
raw
helper to output raw htmlmore information: ActionView::Helpers::OutputSafetyHelper#raw
You can mark the string as
html_safe
more information: String#html_safe and ActiveSupport::SafeBuffer#new
You can sanitize your output with
sanitize
more information: ActionView::Helpers::SanitizeHelper#sanitze
Some more Information: