# Template comments?

**URL:** <https://www.ruby-forum.com/t/template-comments/55758>\
**Category:** Rails\
**Created:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/template-comments/55758 "2005-11-12T12:49:22Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![cool\_screen\_name900](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c68b51/32.png) [@cool\_screen\_name900](https://www.ruby-forum.com/u/cool_screen_name900)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/template-comments/55758/1 "2005-11-12T12:49:22Z")

</div>

Is there a way to put comments in templates (not using  
HTML)? It appears Ruby only supports single-line  
comments (#), and not multiline (/\* … \*/). Right now  
I use:

\<% if 0==1 %\>  
comments …  
\<% end %\>

I think I tried ‘if 0’ but it caused an error.

Thanks,  
csn

* * *

Yahoo! Mail - PC Magazine Editors’ Choice 2005

> **[Yahoo Mail - Organized Email](https://mail.yahoo.com)**
>
> It's time to get stuff done with Yahoo Mail. Just add your Gmail, Outlook, AOL or Yahoo Mail to get going. We automatically organize all the things life throws at you, like receipts and attachments, so you can find what you need fast. Plus, we've got...

---

<div class="post-metadata">

**Author:** ![cool\_screen\_name900](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c68b51/32.png) [@cool\_screen\_name900](https://www.ruby-forum.com/u/cool_screen_name900)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/template-comments/55758/2 "2005-11-12T12:49:23Z")

</div>

try:

=being  
comment  
comment  
comment  
=end

source:  
[http://hao2lian.f2o.org/wiki/pmwiki.php/Articles/Multi-LineCommentsInRuby](http://hao2lian.f2o.org/wiki/pmwiki.php/Articles/Multi-LineCommentsInRuby)

On 11/8/05, CSN [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I think I tried ‘if 0’ but it caused an error.
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–

- Ramin  
[http://www.getintothis.com/blog](http://www.getintothis.com/blog)

---

<div class="post-metadata">

**Author:** ![cool\_screen\_name900](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c68b51/32.png) [@cool\_screen\_name900](https://www.ruby-forum.com/u/cool_screen_name900)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/template-comments/55758/3 "2005-11-12T12:49:23Z")

</div>

On 11/8/05, CSN [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Is there a way to put comments in templates (not using  
> HTML)? It appears Ruby only supports single-line  
> comments (#), and not multiline (/\* … \*/). Right now  
> I use:
> 
> \<% if 0==1 %\>  
> comments …  
> \<% end %\>
> 
> I think I tried ‘if 0’ but it caused an error.

\<%  
=begin

commented code here.

=end  
%\>

> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Bill G. (aka aGorilla)

---

<div class="post-metadata">

**Author:** ![cool\_screen\_name900](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c68b51/32.png) [@cool\_screen\_name900](https://www.ruby-forum.com/u/cool_screen_name900)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/template-comments/55758/4 "2005-11-12T12:49:23Z")

</div>

\<% if nil %\>  
comments …  
\<% end %\>

\<% if false %\>  
comments …  
\<% end %\>

---

<div class="post-metadata">

**Author:** ![cool\_screen\_name900](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c68b51/32.png) [@cool\_screen\_name900](https://www.ruby-forum.com/u/cool_screen_name900)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/template-comments/55758/5 "2005-11-12T12:49:25Z")

</div>

On 11/8/05, CSN [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > I use:
> 
> if/end (unless the comments are outside of \<% …  
> %\>).

odd, as that’s from a template I’ve used recently, and it works fine.

They do have to be on seperate lines because the ‘=’ has to be the 1st  
character on the line. This will _not_ work:

\<% =begin

commented code here.

=end %\>

> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Bill G. (aka aGorilla)

---

<div class="post-metadata">

**Author:** ![cool\_screen\_name900](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c68b51/32.png) [@cool\_screen\_name900](https://www.ruby-forum.com/u/cool_screen_name900)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/template-comments/55758/6 "2005-11-12T12:49:24Z")

</div>

— Bill G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > comments …  
> > \<% end %\>
> > 
> > I think I tried ‘if 0’ but it caused an error.

Actually, what happens is the enclosed code still gets  
executed. ?

> \<%  
> =begin
> 
> commented code here.
> 
> =end  
> %\>

I tried that, but got errors - Ruby appears to try to  
interpret the comments as code. Same goes when using  
if/end (unless the comments are outside of \<% …  
%\>).

csn

* * *

Yahoo! Mail - PC Magazine Editors’ Choice 2005

> **[\[object](https://mail.yahoo.com/)**
>
> \[object

---

<div class="post-metadata">

**Author:** ![cool\_screen\_name900](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c68b51/32.png) [@cool\_screen\_name900](https://www.ruby-forum.com/u/cool_screen_name900)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/template-comments/55758/7 "2005-11-12T12:49:25Z")

</div>

— Bill G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > using
> > > 
> > > > 
> > > 
> > > commented code here.
> 
> =end %\>

Ah, that’s what it was - I had the block indented.

csn

* * *

Yahoo! FareChase: Search multiple travel sites in one click.  
[http://farechase.yahoo.com](http://farechase.yahoo.com)

---

<div class="post-metadata">

**Author:** ![cool\_screen\_name900](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c68b51/32.png) [@cool\_screen\_name900](https://www.ruby-forum.com/u/cool_screen_name900)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/template-comments/55758/8 "2005-11-12T12:49:26Z")

</div>

\<%# comment  
comment  
comment  
comment  
%\>

HTH-  
-Ezra

On Nov 8, 2005, at 2:50 PM, CSN wrote:

> > > I use:
> 
> if/end (unless the comments are outside of \<% …  
> [http://mail.yahoo.com](http://mail.yahoo.com)
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

-Ezra Z.  
WebMaster  
Yakima Herald-Republic Newspaper  
removed\_email\_address@domain.invalid  
509-577-7732

---

<div class="post-metadata">

**Author:** ![cool\_screen\_name900](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c68b51/32.png) [@cool\_screen\_name900](https://www.ruby-forum.com/u/cool_screen_name900)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/template-comments/55758/9 "2005-11-12T12:49:41Z")

</div>

Sweet. Only problem is if there are additional code  
tags in the block, e.g.

\<%#  
comment  
comment  
\<%= @foo %\> ← @foo gets outputted  
comment  
\<% if 1 %\> ← this block causes a syntax error  
bar  
\<% end %\>  
comment  
%\>

Ah well, guess just use ‘if false/end’ around blocks  
like that.

csn

— Ezra Z. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > now  
> > > executed. ?  
> > > I tried that, but got errors - Ruby appears to try
> 
> -Ezra Z.  
> WebMaster  
> Yakima Herald-Republic Newspaper  
> removed\_email\_address@domain.invalid  
> 509-577-7732
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

* * *

Yahoo! Mail - PC Magazine Editors’ Choice 2005

> **[\[object](https://mail.yahoo.com/)**
>
> \[object
