views:

114

answers:

3

How do you comment out html mixed with ruby code?

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

In jsp it's real simple: <%-- ... --%>, but I'm unable to find any concise option in rails.

Simple html comments <!-- ... --> do not work: ruby code is still executed and yells errors.

There's an option to use if false with html comments, but it's quite verbose, not to mention IDEs doesn't support it.

There's also an option coming from pure ruby, which surprisingly works.

<%
=begin %>
... html and ruby code goes here
<%
=end %>

It's generally fine, except that it's verbose, weird-looking and none of ruby IDEs I know support it (yep, I like to comment/comment-out with one keystroke).

I'm curious, is there any 'official' of doing this in rails?

Thanks!

+1  A: 
John Topley
1) you're right, jsp comments have slightly different format, I updated the post. 2) I can't find anything like that in IDEA or Netbeans. Did you have anything any particular IDE in mind saying this?
Nikita Rybak
No I didn't. Personally, I don't use an IDE for Rails projects.
John Topley
A: 

Use this for commenting single lines:

<%# your_ruby_code %>

For multiple lines, the

<% 
=begin %>  <% ruby_code %>
<% 
=end %>

What you said would work.

Shikher
I know it would, I'm interested if there's anything simpler :)
Nikita Rybak
=beginI think the begin - end would be all =end# You may ignore my comment as its entirely commented :P
Shikher
+1  A: 

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.

Chubas
yep, my sentiments exactly
Nikita Rybak