最近看到这个,觉得很有趣。但是我真的不明白它的作用?
例。我有一个 Rails 应用程序,我想引导一些 json,这样我就不必发出第二个请求。通常我会写这样的东西。
<%= raw @model.to_json %>
或者
<%= @model.to_json.html_safe %>
我必须发送消息 raw
或 html_safe
否则 json 将被 html 转义,因此无法正确解析。但是,这似乎也有效。
<%== @model.to_json %>
但是我找不到任何文档。
有谁知道这到底是做什么的?即它与调用 html_safe
完全相同吗?或 raw
?或者还有更多?
最佳答案
<%==
相当于raw
.
To insert something verbatim use the
raw
helper rather than callinghtml_safe
:<%= raw @cms.current_template %> <%# inserts @cms.current_template as is %>
or, equivalently, use
<%==
:<%== @cms.current_template %> <%# inserts @cms.current_template as is %>
关于ruby-on-rails - <%== %> 在 Rails erb 中做什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13142326/