What does <%== %> do in rails erb?

后端 未结 2 936
长情又很酷
长情又很酷 2020-12-02 14:36

I saw this recently, thought it was interesting. But I don\'t really understand what it does?

Ex. I have a rails app and I want to bootstrap some json, so that I d

相关标签:
2条回答
  • 2020-12-02 14:42

    <%== is equivalent to raw.

    From the Ruby on Rails Guide:

    To insert something verbatim use the raw helper rather than calling html_safe:

    <%= raw @cms.current_template %> <%# inserts @cms.current_template as is %>
    

    or, equivalently, use <%==:

    <%== @cms.current_template %> <%# inserts @cms.current_template as is %>
    
    0 讨论(0)
  • 2020-12-02 14:47

    Rails actually uses Erubis instead of ERB, which supports a variety of other stuff.

    <%== is exactly as you expect, though: It emits the value unescaped

    0 讨论(0)
提交回复
热议问题