Active Record forgets methods! bug?

I have created a rails app.
When in development mode, I hit a problem the second time I try to
display a page from a particular controller: it raises a method_missing
exception because suddenly the model I am trying to use has forgotten
about all the methods I added to it, and all its association methods
(from has_one and has_many). Inspecting the model shows that it still
has it’s @attributes array.

In production mode, it works fine. Same result on Rails 1.x and 2.0.2.
Below is an example exception. In my DB, System has_many

Any ideas?

undefined method `test_results’ for #System:0x2521eb0

Application Trace | Framework Trace | Full Trace
method_missing' app/controllers/results_controller.rb:34:inreport’
each' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/associations/association_proxy.rb:125:insend’
method_missing' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/associations/has_many_through_association.rb:133:inmethod_missing_without_paginate’
method_missing' app/controllers/results_controller.rb:32:inreport’
<snip - boring part deleted>

This is because of the file loading problem in development mode.
So for this, add the following statement on top of the ‘system.rb’ file.

requrie ‘test_result.rb’

Use the file names that you are using. I have given the file names in

I hope it will work. Because I have experienced the same problem.

  • Karthik.

Sorry Karthink -> Karthik

Many thanks for your suggestion Karthink.
That was a good idea: require ‘test_result’ was indeed missing from

Unfortunately this did not solve the problem.
Something more sinister is going on.


I dont know what else the problem is.

Did you restart the server after adding the statement? If not, please
try that also.

Karthi kn wrote:

Did you restart the server after adding the statement? If not, please
try that also.

Yes. Twice :slight_smile:

Can you show that controller code here?

Karthi kn wrote:

Can you show that controller code here?

No need - you cracked it!
I went further and put in appropriate require statements for EVERY
association in EVERY model.
That fixed it. I have some 2-step joins (using :through) and I think
one of those maybe was causing the problem.

Many thanks for your help!


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs