Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to comment lines in rails html.erb files? [duplicate]

Am a newbie to rails , please let me know the way to comment out a single line and also to comment out a block of lines in *.html.erb files.

like image 832
Hemanth Avatar asked Oct 10 '10 18:10

Hemanth


People also ask

How do I comment in an erb file in HTML?

To comment one line I must use 3 additional characters, and the block comment is nothing but code that will be not executed - no other color coding that makes it very unpractical to see which code is not executed on first look. @gotqn Then you will LOVE HAML!

How do you comment out an ERB code?

%>\n <% end #____/\____/\____/\____%> . This makes the comment area obvious.

How do you comment code in Rails?

-- --> as a comment. As the other answers said, use <% #comment %> to comment within a Rails view.

How do you comment in Ruby on Rails?

The Ruby single-line comment begins with the # character and ends at the end of the line. Any characters from the # character to the end of the line are completely ignored by the Ruby interpreter.


2 Answers

ruby on rails notes has a very nice blogpost about commenting in erb-files

the short version is

to comment a single line use

<%# commented line %> 

to comment a whole block use a if false to surrond your code like this

<% if false %> code to comment <% end %> 
like image 186
Nikolaus Gradwohl Avatar answered Sep 21 '22 20:09

Nikolaus Gradwohl


Note that if you want to comment out a single line of printing erb you should do like this

<%#= ["Buck", "Papandreou"].join(" you ") %> 
like image 21
Gerry Avatar answered Sep 19 '22 20:09

Gerry