264

How do we add comments in erb files, if we do not want them to be generated into the html content?

thumbtackthief
  • 5,585
  • 6
  • 36
  • 72
Kalyan Maddu
  • 3,957
  • 2
  • 19
  • 26

7 Answers7

370

Use the <%# %> sequence, e.g.

<%# This is a great comment! %>
John Douthat
  • 39,186
  • 10
  • 62
  • 65
  • I used to use this format until I noticed it just raised an error on someones computer in my team (we were both using linux, but different distros), regardless I avoid it since.. – vise May 05 '10 at 21:57
  • 4
    It's one of only a few supported ERB tags. http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html If it didn't work on their PC, they either had a typo, or they weren't using real ERB. However, I've run into issues with code like this .. This was OK in the ERB that shipped with 1.8.6, but when I switched to 1.8.7, it caused lots of problems. – John Douthat May 05 '10 at 22:20
  • 20
    i.e. there can't be any space between ` – John Douthat May 05 '10 at 22:30
  • How can i get textmate to generate these style of comments with apple-/ – Michael Aug 10 '10 at 22:39
  • 2
    @Mike Ctrl+Shift+Period (i.e. Ctrl+GreaterThan) 4 times quickly should do it. – John Douthat Aug 11 '10 at 16:02
  • This occasionally fails in some rubys... I find you need to put the closing "%>" tag on a newline... which feels a bit kludgy, but means you don't suddenly find half your template disappears on production, even though it works find on development :P – Taryn East Nov 07 '11 at 15:55
  • @TarynEast: be sure there aren't any characters between ` – John Douthat Nov 07 '11 at 18:13
  • I have some problem commenting this
  • ... since I have "%>" already in the erb. How should I comment "
  • "?? – WowBow Jun 10 '12 at 20:26
  • By the way, for those using sublimetext2 .. check out https://github.com/eddorre/SublimeERB – Abram Dec 27 '12 at 03:25
  • I was using this but found it doesn't work if I want to comment out a section of existing code that already contains a closing tag %> (because the comment ends at the first closing tag). So now I'm using the suggestion by user user3212755. Does anyone have any other suggestions? – TMin Feb 14 '15 at 16:38