# Suggestions for commenting/documenting view (.rhtml) files?

**URL:** <https://www.ruby-forum.com/t/suggestions-for-commenting-documenting-view-rhtml-files/114548>\
**Category:** Rails\
**Created:** [September 14, 2007, 7:03pm UTC](https://www.ruby-forum.com/t/suggestions-for-commenting-documenting-view-rhtml-files/114548 "2007-09-14T19:03:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [September 14, 2007, 7:03pm UTC](https://www.ruby-forum.com/t/suggestions-for-commenting-documenting-view-rhtml-files/114548/1 "2007-09-14T19:03:05Z")

</div>

I’m writing up my RoR degree project (the project is RoR, not the  
degree!), and am unsure of how to document/comment the .rhtml files.  
Has anyone else done this before or have any recommendations/suggestion?

Is it best to just do everything in ? This seems  
a bit wrong to me for some reason.

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [September 17, 2007, 10:15am UTC](https://www.ruby-forum.com/t/suggestions-for-commenting-documenting-view-rhtml-files/114548/2 "2007-09-17T10:15:10Z")

</div>

\<%= this is dislayed on page %\>  
\<% this is pure ruby hidden from page %\>

\<%# and this is a comment, nothing happens here %\>

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [September 17, 2007, 10:53am UTC](https://www.ruby-forum.com/t/suggestions-for-commenting-documenting-view-rhtml-files/114548/3 "2007-09-17T10:53:22Z")

</div>

Shai R. wrote:

> \<%= this is dislayed on page %\>  
> \<% this is pure ruby hidden from page %\>
> 
> \<%# and this is a comment, nothing happens here %\>

ah…doesn’t the ruby interpreter have a problem with these lines then?  
I thought it would say “unknown method or attribute ‘this’” or  
something.

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [September 17, 2007, 10:59am UTC](https://www.ruby-forum.com/t/suggestions-for-commenting-documenting-view-rhtml-files/114548/4 "2007-09-17T10:59:01Z")

</div>

Max W. wrote:

> Shai R. wrote:
> 
> > \<%= this is dislayed on page %\>  
> > \<% this is pure ruby hidden from page %\>
> > 
> > \<%# and this is a comment, nothing happens here %\>
> 
> ah…doesn’t the ruby interpreter have a problem with these lines then?  
> I thought it would say “unknown method or attribute ‘this’” or  
> something.

just as in a ruby file, the ‘#’ means a comment until the end of the  
line.  
this will give you an error:

\<%# will raise a parsing error  
(the opening erb \<% and matching closing one arent on the same line  
%\>

but, you could use comments in erb like so

\<%

# all of these

# are

# lines

# but the one below me is not

a = 13  
%\>

\<%# this is comment as well %\>

\<%  
=begin  
all of the blah blah  
here is  
one big  
multiple line comment, but after the =end  
it is plain erb  
=end

a = 13  
%\>

enjoy

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [September 17, 2007, 1:23pm UTC](https://www.ruby-forum.com/t/suggestions-for-commenting-documenting-view-rhtml-files/114548/5 "2007-09-17T13:23:12Z")

</div>

On Fri, 14 Sep 2007, Max W. wrote:

> […] and am unsure of how to document/comment the .rhtml files. […]
> 
> Is it best to just do everything in ? This seems  
> a bit wrong to me for some reason.

You can comment the ruby code inside them thusly:

\<%

# This next method is only used in this file, and doesn’t

# belong anywhere else

def do\_amazing\_magic(spells={})  
SufficientlyAdvancedTechnology.execute(spells)  
end  
%\>

```
    HTH
    Hugh
```

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [September 17, 2007, 11:01am UTC](https://www.ruby-forum.com/t/suggestions-for-commenting-documenting-view-rhtml-files/114548/6 "2007-09-17T11:01:16Z")

</div>

> \<%
> 
> # all of these
> 
> # are
> 
> # lines
> 
> # but the one below me is not
> 
> a = 13  
> %\>

this is great - thanks!

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [September 17, 2007, 2:37pm UTC](https://www.ruby-forum.com/t/suggestions-for-commenting-documenting-view-rhtml-files/114548/7 "2007-09-17T14:37:57Z")

</div>

Hugh S. wrote:

> On Fri, 14 Sep 2007, Max W. wrote:
> 
> > […] and am unsure of how to document/comment the .rhtml files. […]
> > 
> > Is it best to just do everything in ? This seems  
> > a bit wrong to me for some reason.
> 
> You can comment the ruby code inside them thusly:
> 
> \<%
> 
> # This next method is only used in this file, and doesn’t
> 
> # belong anywhere else
> 
> def do\_amazing\_magic(spells={})  
> SufficientlyAdvancedTechnology.execute(spells)  
> end  
> %\>
> 
> ```
> HTH
> Hugh
> 
> ```

That’s cool, i didn’t realise you could put entire blocks of ruby code  
within \<% %\> - i’d been doing one per line. Thanks!

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [September 17, 2007, 3:11pm UTC](https://www.ruby-forum.com/t/suggestions-for-commenting-documenting-view-rhtml-files/114548/8 "2007-09-17T15:11:42Z")

</div>

Hugh S. wrote:

> \<%
> 
> # This next method is only used in this file, and doesn’t
> 
> # belong anywhere else
> 
> def do\_amazing\_magic(spells={})  
> SufficientlyAdvancedTechnology.execute(spells)  
> end  
> %\>

Care to share your SufficientlyAdvancedTechnology class? [grin]
