Feature #11624


ERB deserves its own commenting token

Added by Adamantish (Adam Misrahi) about 8 years ago. Updated over 6 years ago.

Target version:



  • ERB is a DSL but commenting out code is not the easy workflow feature in ERB that it is in other languages.
  • ERB elements were cleverly designed to look like a special kind of html element so it makes programmers unhappy and surprised when commenting the HTML does not affect the ruby elements nested inside.
  • This makes certain workflows particularly difficult e.g. sketching out a view to aide with iteratively developing its underlying model.


This proposes a new set of ERB commenting tokens - currently for use with HTML only.
They take the form of an HTML comment combined with a Ruby comment.
Looks like this:

None of this will be outputted: <%= my_ruby_var %>
and neither will this


This patch takes a cautious approach. Legacy ERB files may contain typos which happen to match ERB comment token. These are invalid HTML but may have been tolerated and simply printed out in the displayed webpage. For this reason the implementation ignores the ERB comment tokens unless they are properly closed off. This greatly reduces the likelihood of legacy issues and if they do arise they will not disrupt intended functionality.

Personal note

I realise I can't suggest anything that hasn't been thought of already. I see that the main reason this hasn't already been implemented is probably because ERB is not just for HTML. However, it may be that a pair of tokens can be found and proven to be compatible with most languages.

Thousands of people clearly continue to want this and the hackiness of the accepted answers on stack overflow shows how others have just gotten used to doing it the hard way.

I'd just really like to see this solved even if none of my code is used.


erb_patch.rb (4.31 KB) erb_patch.rb diffed with trunk on github commit 9e52416cd304c648e7bf49f1e77c81cd5adac506 Adamantish (Adam Misrahi), 10/27/2015 04:18 PM

Updated by nobu (Nobuyoshi Nakada) about 8 years ago

  • Description updated (diff)
  • Status changed from Open to Assigned
  • Assignee set to seki (Masatoshi Seki)

Updated by hsbt (Hiroshi SHIBATA) over 6 years ago

  • Assignee changed from seki (Masatoshi Seki) to k0kubun (Takashi Kokubun)
  • Target version set to 2.5

Updated by k0kubun (Takashi Kokubun) over 6 years ago

  • Status changed from Assigned to Rejected

This syntax only adds a support for comments that include "%>" or "%%>". I think the major use case of such kind of feature is just ad-hoc disabling partial template and it's not for a normal permanent comment, which can be done in "<%#". So I think its use case is limited compared to "<%#"'s one.

The downside of this feature is slowing down compilation. It will be reported as a bug like [Bug #12074].

Comparing merits and demerits, for now, I reject this feature in ERB and solve your problem with third-party library

If you want to use it on Rails, you may need to port this to Erubi. If main use case is web application (it's not the case for ERB), it's less important to care about compilation cost. So it'll be a good idea to have such a feature in Erubi.


Also available in: Atom PDF