# Missing assocation methods (public\_instance\_methods.length == 0 for an active record model)

**URL:** <https://www.ruby-forum.com/t/missing-assocation-methods-public-instance-methods-length-0-for-an-active-record-model/115547>\
**Category:** Rails\
**Created:** [September 26, 2007, 5:26am UTC](https://www.ruby-forum.com/t/missing-assocation-methods-public-instance-methods-length-0-for-an-active-record-model/115547 "2007-09-26T05:26:56Z")\
**Posts on this page:** 3\
**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:** [September 26, 2007, 5:26am UTC](https://www.ruby-forum.com/t/missing-assocation-methods-public-instance-methods-length-0-for-an-active-record-model/115547/1 "2007-09-26T05:26:56Z")

</div>

Hi all,

I’m getting a weird “transient” error I’m hoping someone can shed some  
light on.

In short, the first time view a particular page all is well. The  
second time around, I get a bunch of active record model objects with  
no public\_instance\_methods, so all code relying on that fails. Server  
restart is required to fix it.

I have a method in one of my models that goes through several  
associated models, iterates over the associated model objects and  
further iterates into associated models on those to return some  
distantly related model objects.

It works great… but only once for every server load. If I refresh the  
page, subsequent calls to the accessor methods for the associations  
have no methods!! So I get undefined method for something that clearly  
existed just one refresh ago!

To give some more details, I have a Volunteer which has  
VolunteerApplications which each have an Opportunity which each have  
an Organization.

I want to get the organizations for a given volunteer… So I do so via

has\_many :opportunities, :through =\> :volunteer\_applications

which has created the opportunities method for me. I call that and  
iterate over each and call organization on each (which was created by:  
belongs\_to :organization )

But upon refresh the organization accessor doesn’t exist for  
opportunity, nor does any other.

Any clues? Ideas of how to better debug this? I’ve confirmed via  
debugger that the attributes are all set on the model object, but it  
has none of the association methods added by has\_many, belongs\_to,  
etc.

I’ve also confirmed that belongs\_to, etc are in fact being run.

Thanks in advance!  
– Luke

---

<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:** [September 26, 2007, 5:50am UTC](https://www.ruby-forum.com/t/missing-assocation-methods-public-instance-methods-length-0-for-an-active-record-model/115547/2 "2007-09-26T05:50:18Z")

</div>

I’d just like to add that this problem doesn’t occur in the test or  
production environments, only development.  
Also, we are running Rails 1.2.3 over Ruby 1.8.5

---

<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:** [September 26, 2007, 6:48am UTC](https://www.ruby-forum.com/t/missing-assocation-methods-public-instance-methods-length-0-for-an-active-record-model/115547/3 "2007-09-26T06:48:09Z")

</div>

Solved.

Once upon a time this would have involved using  
model :blah

in the Controller… But I hear that’s deprecated. So I just required  
the models… and it’s fine. Not an easy thing to troubleshoot though…

– Luke
