# Very odd NoMethodError/stack overflow

**URL:** <https://www.ruby-forum.com/t/very-odd-nomethoderror-stack-overflow/156792>\
**Category:** Rails\
**Created:** [January 2, 2009, 11:48pm UTC](https://www.ruby-forum.com/t/very-odd-nomethoderror-stack-overflow/156792 "2009-01-02T23:48:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 2, 2009, 11:48pm UTC](https://www.ruby-forum.com/t/very-odd-nomethoderror-stack-overflow/156792/1 "2009-01-02T23:48:45Z")

</div>

I’m getting this very weird error and I can’t figure out what the  
problem is. I’m using acts\_as\_commentable. Basically, I have a partial  
with this code in it:

\<%= link\_to comment.user.login, profile\_path(User.find (comment.user\_id).profile) %\>\<%= comment.comment %\>

and here’s the code that calls the partial:

\<% @comments.each do |comment| %\>  
\<%= render :partial =\> ‘partials/comment’, :locals =\> {:comment =\>  
comment} %\>  
\<% end %\>

profile\_path(User.find(comment.user\_id).profile) is the hack I’ve had  
to do to avoid this problem which is weird. All users have a profile,  
so they are accessible by user.profile. I get the stack overflow error  
when I do comment.user.id, but accessing comment.user.login or any  
other attribute works fine. When I do comment.user.profile I get the  
NoMethodError. I’ve checked over and over and all associations are in  
place…nothing seems wrong to me, yet this error won’t go away. What  
could be the problem? ☹

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 3, 2009, 12:02am UTC](https://www.ruby-forum.com/t/very-odd-nomethoderror-stack-overflow/156792/2 "2009-01-03T00:02:49Z")

</div>

> profile\_path(User.find(comment.user\_id).profile) is the hack I’ve had  
> to do to avoid this problem which is weird. All users have a profile,  
> so they are accessible by user.profile. I get the stack overflow error  
> when I do comment.user.id, but accessing comment.user.login or any  
> other attribute works fine. When I do comment.user.profile I get the  
> NoMethodError. I’ve checked over and over and all associations are in  
> place…nothing seems wrong to me, yet this error won’t go away. What  
> could be the problem? ☹

You could start by showing the models that seem to be causing the  
problem 🙂

Fred

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 3, 2009, 2:32am UTC](https://www.ruby-forum.com/t/very-odd-nomethoderror-stack-overflow/156792/3 "2009-01-03T02:32:40Z")

</div>

Quoting Mike C [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> ```
> <dd><%= comment.comment %></dd>
> 
> ```
> 
> profile\_path(User.find(comment.user\_id).profile) is the hack I’ve had  
> to do to avoid this problem which is weird. All users have a profile,  
> so they are accessible by user.profile. I get the stack overflow error  
> when I do comment.user.id, but accessing comment.user.login or any  
> other attribute works fine. When I do comment.user.profile I get the  
> NoMethodError. I’ve checked over and over and all associations are in  
> place…nothing seems wrong to me, yet this error won’t go away. What  
> could be the problem? ☹

I’ve found model.id problematic. I now always use model[:id] and have  
had  
fewer problems, none related to ambiquities around object ID versus  
record ID,  
etc.

Jeffrey

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 3, 2009, 12:13am UTC](https://www.ruby-forum.com/t/very-odd-nomethoderror-stack-overflow/156792/4 "2009-01-03T00:13:22Z")

</div>

class Comment \< ActiveRecord::Base  
belongs\_to :commentable, :polymorphic =\> true

# NOTE: install the acts\_as\_votable plugin if you

# want user to vote on the quality of comments.

#acts\_as\_voteable

# NOTE: Comments belong to a user

belongs\_to :user  
…  
end

class Story \< ActiveRecord::Base  
acts\_as\_commentable  
acts\_as\_taggable\_on :tags  
has\_many :cores  
belongs\_to :user

validates\_presence\_of :title  
validates\_presence\_of :description  
validates\_presence\_of :rules  
validates\_length\_of :title, :within =\> 3…50  
end

class User \< ActiveRecord::Base  
…  
has\_many :stories  
has\_many :cores  
has\_many :comments  
has\_one :profile  
…  
end

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 3, 2009, 2:35am UTC](https://www.ruby-forum.com/t/very-odd-nomethoderror-stack-overflow/156792/5 "2009-01-03T02:35:35Z")

</div>

Thanks. That fixed that problem…but the other problem still exists. :  
(

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 4, 2009, 1:36am UTC](https://www.ruby-forum.com/t/very-odd-nomethoderror-stack-overflow/156792/6 "2009-01-04T01:36:24Z")

</div>

With the help of a friend, I’ve found what’s causing the error. In the  
will\_paginate plugin under tests/fixtures is a user.rb class defined  
as class User ActiveRecord::Base. Rails was using that one instead of  
one in my app/model. My new question is, why was it doing this? It  
shouldn’t have loaded that one, right?
