Block comments in html.erb templates in rails

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

How do you comment out html mixed with ruby code?

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

In js

16条回答
  •  旧时难觅i
    2020-12-07 09:41

    Use a HEREDOC called comment

    Pros:

    • Self-explanatory that this is a comment
    • Works for erb and HTML tags
    • Has ok syntax highlighting (as one long string)

    Cons:

    • Weird 3 line closing syntax
    • No keyboard shortcuts

    Code:

    The opening tag can be

    <% <<-COMMENT %>
    
    the above closing erb tag is just for looks (to match the end),
    but don't put anything else there, it may show up on the page
    

    or

    <%
    <<-COMMENT
    %>
    

    Anything here won't run or show up in the browser

    this will not be displayed in the browser even in the developer's tools

    <% 1_000_000_000_000.times do |count| %> for the <%= count %>'th time, this won't run a trillion times, this is all just a string all of these %>, <%, <% end %>, end, do,
    热议问题