Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to comment code in Rails views?

As I'm playing with Rails and developing views I often want to comment out code. Simple enough with classes & models but views are a bit more tricky.

What's best way to comment code in a view so it's not interpreted by, well, anything... HTML gives us <!-- commented Rails code here --> though code enclosed here seems to get interpreted anyway?!? Or is there a more Railsy way?

like image 974
Meltemi Avatar asked Jun 22 '10 18:06

Meltemi


1 Answers

<% code code # comment %> USED to work but I think that was accidental.

You were always supposed to put comments in separate comment tags <%# comment %>

Note NO SPACE before the pound.

Now the old loophole is closed (I forget whether 'now' means Ruby 1.8 or Rails 3 or what) so that:

<% code code  #  this runs too %>
<% # also runs %>
<%# the only way to comment out %>
like image 63
elc Avatar answered Sep 22 '22 13:09

elc