Block comments in html.erb templates in rails

前端 未结 16 2158
北荒
北荒 2020-12-07 09:10

How do you comment out html mixed with ruby code?

some text <% ... %> more text <%= ... %>
something else
<% ... %>

In js

相关标签:
16条回答
  • 2020-12-07 10:01
    <%#=
    
    ...commented
    multiline
    block...
    
    %>
    
    0 讨论(0)
  • 2020-12-07 10:04

    I wouldn't count as a solution, but perhaps enclosing the chunk between an

    <% if false %>
       ...
    <% end %>
    

    or if you feel a little dirty, create a helper that simply outputs nothing.

    I've never needed it, but I'm stumbled there seems to be no out-of-the-box solution for this.

    0 讨论(0)
  • 2020-12-07 10:04

    To comment out erb tags use the ruby comment hash symbol before the = sign in the opening tag

    <p>
     This is some text I want to keep
     <%= @some_object.some_attribute %>
    </p>
    <p>
      I want to keep this text but comment out the erb tag
      <%#= @some_object.another_attribute %>
    </p>
    <!--
    <p>
      I want all of this text commented out including the erb tag
      <%#= @some_object.some_attribute %>
    </p>
    -->
    <!--
    <p>
     I just want this html commented out but I want to keep the erb tag
     <%= @some_object.some_attribute %>
    </p>
    -->
    
    0 讨论(0)
  • 2020-12-07 10:06

    This is the onlyone that worked for me.

    <%
    =begin %>
    
    code code code code code code 
    code code code code code code 
    code code code code code code 
    code code code code code code 
    
    =end %>

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