Rails 3 - How to comment in a View?

Viewed 11494

What is the Rails 3 way to comment out One Line or Multiple lines of code in a View? And so it doesn't show up in the HTML Source

5 Answers

Here's what I do to hide comments from HTML (...whatever, it works!)

in your helpers/application.rb file:

def comment
    # use this keyword in the views, to comment-out stuff...
end

in your view:

<h3><% comment = "my Rails-y something something here will not be visible to HTML.
    I don't know why I have to comment stuff out in this manner.
    It's probably not the 'Rails Way' but ...it works for me.
    It would be nice if Rails 3 had some kind of comment-out feature like <%## %> or <%-- --%>  or something like that...
    Ah, well... 
    At least they won't be able to 'View Source' and read this comment! ;]
" %></h3>

what 'View Source' shows:

<h3></h3>

C-YA!

Related