# NoMethodError after refresh?

**URL:** <https://www.ruby-forum.com/t/nomethoderror-after-refresh/153310>\
**Category:** Rails\
**Created:** [November 14, 2008, 6:02pm UTC](https://www.ruby-forum.com/t/nomethoderror-after-refresh/153310 "2008-11-14T18:02:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![magic6435](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/57b2e6/32.png) [@magic6435](https://www.ruby-forum.com/u/magic6435)\
**Post date:** [November 14, 2008, 6:02pm UTC](https://www.ruby-forum.com/t/nomethoderror-after-refresh/153310/1 "2008-11-14T18:02:31Z")

</div>

This is strange. I’m working on a simple comment system but it has a  
fit when displaying the user names after the first time the page is  
loaded. so if i start the webserver then go to the page everything  
works fine but if i then refresh i get this error. if i remove the  
user.login it works fine always. Also i have other places in the site  
that show the Mode.user.login and they work fine

ActionView::TemplateError (You have a nil object when you didn’t  
expect it!  
You might have expected an instance of Array.  
The error occurred while evaluating nil.include?) on line #12 of app/  
views/bids/show.html.erb:  
11: \<% @bid.comments.each do |comment| %\>  
12: \<%= comment.user.login %\>  
13: \<%= simple\_format(comment.comment) %\>  
14: \<% end %\>  
15:

Any one got an idea of why this is happening? if i set the dev env to  
cache classes then it has no problems…  
config.cache\_classes = true

Thanks for any help.

---

<div class="post-metadata">

**Author:** ![magic6435](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/57b2e6/32.png) [@magic6435](https://www.ruby-forum.com/u/magic6435)\
**Post date:** [November 14, 2008, 6:42pm UTC](https://www.ruby-forum.com/t/nomethoderror-after-refresh/153310/2 "2008-11-14T18:42:22Z")

</div>

Typically this means you have confused rails’ dependency system. One  
way you can achieve that is using require to load your application  
classes instead of require\_dependency. I wrote a blog post about that  
not too long ago. You should be able to find it if you google for  
“required or not”

Fred

Sent from my iPhone

On 14 Nov 2008, at 17:01, “removed\_email\_address@domain.invalid” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![magic6435](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/57b2e6/32.png) [@magic6435](https://www.ruby-forum.com/u/magic6435)\
**Post date:** [November 15, 2008, 4:58pm UTC](https://www.ruby-forum.com/t/nomethoderror-after-refresh/153310/3 "2008-11-15T16:58:51Z")

</div>

Ah thanks ill give that a try.

On Nov 14, 12:41 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
