# Comments in RHTML files

**URL:** <https://www.ruby-forum.com/t/comments-in-rhtml-files/129333>\
**Category:** Rails\
**Created:** [February 16, 2008, 11:08pm UTC](https://www.ruby-forum.com/t/comments-in-rhtml-files/129333 "2008-02-16T23:08:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![martin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/73ab20/32.png) [@martin](https://www.ruby-forum.com/u/martin)\
**Post date:** [February 16, 2008, 11:08pm UTC](https://www.ruby-forum.com/t/comments-in-rhtml-files/129333/1 "2008-02-16T23:08:36Z")

</div>

Hello all,

I have a Partial and at the beginning of it I have Ruby code (\<% …  
%\>) in which a have a couple of comments. When the comments (which  
starts with #) are in the Partial, my partial is not displayed, when I  
remove them my Partial works. Why?

Here is the beginning of the partial :

\<%

# Check if we passed to the partial the User object

user = User.find\_by\_id(session[:userId]) if  
local\_assigns[:user].nil?

%\>

\<% form\_id = “myPartial\_form”;  
…

---

<div class="post-metadata">

**Author:** ![martin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/73ab20/32.png) [@martin](https://www.ruby-forum.com/u/martin)\
**Post date:** [February 18, 2008, 1:20am UTC](https://www.ruby-forum.com/t/comments-in-rhtml-files/129333/2 "2008-02-18T01:20:44Z")

</div>

I believe the problem is that the \<%# sequence is leading ERb to  
interpret the entire block as a comment, not simply the one line that  
you intend as a comment.

More broadly speaking, it’s a bad idea to be doing ActiveRecord finds  
in your views. They should only be fed data (via locals or instance  
variables) and render. You might consider using a before\_filter that  
creates a @current\_user (for all controllers) by reading in from the  
users table and then simply testing for @current\_user.nil?
