Multiline Comments in Rails ERB Views

If you want to add multiline comments to your Rails .html.erb Views do the following.
The =begin and =end need to be at the beginning of the lines for it to work!
Also, you cannot have any ERB code in the =begin and =end blocks, if you comment this way.

<%
=begin
This is a multiline comment you can add to your .html.erb files. 
Whatever you place in these comments won't show up in your rendered HTML.
You now have a place to put comments in your views. This will help
you better understand what you did later on.
=end %>

If you want to comment out ERB code, you can do something like this, but you have to do it for each line. Just add -# to each line. For example, if you want to comment out this call to render a partial, do the following:

<%-#= render :partial => "configuration", :locals => {:host => host } %>
VN:F [1.9.22_1171]
Rating: 3.8/5 (17 votes cast)
VN:F [1.9.22_1171]
Rating: -2 (from 8 votes)
Multiline Comments in Rails ERB Views, 3.8 out of 5 based on 17 ratings
Facebook Twitter Email

Leave a Reply