# Strange NoMethodErrors in production mode, I just don't know what to do

**URL:** <https://www.ruby-forum.com/t/strange-nomethoderrors-in-production-mode-i-just-dont-know-what-to-do/174916>\
**Category:** Rails\
**Created:** [September 4, 2009, 1:24am UTC](https://www.ruby-forum.com/t/strange-nomethoderrors-in-production-mode-i-just-dont-know-what-to-do/174916 "2009-09-04T01:24:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![msmsms](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/34f0e0/32.png) [@msmsms](https://www.ruby-forum.com/u/msmsms)\
**Post date:** [September 4, 2009, 1:24am UTC](https://www.ruby-forum.com/t/strange-nomethoderrors-in-production-mode-i-just-dont-know-what-to-do/174916/1 "2009-09-04T01:24:07Z")

</div>

Hi,

thanks for reading. Since hours, I am facing a problem and it seems  
that I am not able to solve it.

Let’s say, I’ve got a model called “AnnotationType”. This model has  
got a method called “foobar(x)”. It’s just so simple. I can access  
this method in my unit tests, in the console (all modes), but if I  
start the server in production mode and try to access this method from  
within a view, it can just be found on the first request. Afterwards,  
this method isn’t found anymore:

undefined method `foobar’ for #AnnotationType:0x7f7be4728870

vendor/rails/activerecord/lib/active\_record/attribute\_methods.rb:  
256:in `method_missing' vendor/rails/activerecord/lib/active_record/associations/ association_proxy.rb:177:in`send’  
vendor/rails/activerecord/lib/active\_record/associations/  
association\_proxy.rb:177:in `method_missing' lib/ui/user_interface_renderer.rb:114:in`create\_common\_display\_element’  
…

As you can see, my user interface renderer calls this method, but it  
can’t be found. Of course, it is not the name of an association proxy.  
This explains the above lines.

As I said, and yes, I swear: this method exists! 🙂

I am really thankful for any hint!

Cheers,  
ms

---

<div class="post-metadata">

**Author:** ![msmsms](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/34f0e0/32.png) [@msmsms](https://www.ruby-forum.com/u/msmsms)\
**Post date:** [September 4, 2009, 1:36am UTC](https://www.ruby-forum.com/t/strange-nomethoderrors-in-production-mode-i-just-dont-know-what-to-do/174916/2 "2009-09-04T01:36:25Z")

</div>

make sure the production application was restarted correctly!  
(it happened to me… )

---

<div class="post-metadata">

**Author:** ![msmsms](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/34f0e0/32.png) [@msmsms](https://www.ruby-forum.com/u/msmsms)\
**Post date:** [September 4, 2009, 1:46am UTC](https://www.ruby-forum.com/t/strange-nomethoderrors-in-production-mode-i-just-dont-know-what-to-do/174916/3 "2009-09-04T01:46:57Z")

</div>

Hi,

thanks for your device, but I also tried this. I restarted my whole  
machine to be sure. But it does not work. I found out something new:  
If I include this method from a module, it can be found. But all the  
other methods are not found - also the association proxies!

It seems to me, that rails just instantiates a raw ActiveRecord object  
just with the name of my model. The list of methods you get with  
“.methods()” only contains the default inherited methods. I am  
absolutely confused.

Maybe another idea?

Thank you all.

---

<div class="post-metadata">

**Author:** ![msmsms](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/34f0e0/32.png) [@msmsms](https://www.ruby-forum.com/u/msmsms)\
**Post date:** [September 4, 2009, 10:40am UTC](https://www.ruby-forum.com/t/strange-nomethoderrors-in-production-mode-i-just-dont-know-what-to-do/174916/4 "2009-09-04T10:40:50Z")

</div>

Hi,

I am very thankful for you answer.

Let me answer you points: Yes, it’s the same machine and I use the  
same server: webrick. You second point: Before my post, I copied the  
configurations from the test environment to development environment  
and then I’ve got no problems. As you mentioned, the  
config.action\_controller.perform\_caching ist the problem. If it is set  
to false, I face the problems described. But development with  
config.action\_controller.perform\_caching set to true does not reload  
the source code after a new request, so I have to restart the server  
every time I make changes to the source.

Last night, I tried to get some more information about the problem: as  
I mentioned, the error appears, when I do the second request in the  
webbrowser. The first access is always successful. I put out the  
“.methods()” list of the model instance and there I could see, that my  
own methods are not listed. Also the access methods of the association  
proxies seem not to be existent anymore.

Then I tried the following: I extracted my methods and put them into a  
module. I included this module and suddenly those methods I extracted  
were existent again, also after a few reloads. But still, the  
association proxy methods are missing. I can’t explain this to me.

Do you have another idea?

Thank you very much.  
ms

---

<div class="post-metadata">

**Author:** ![msmsms](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/34f0e0/32.png) [@msmsms](https://www.ruby-forum.com/u/msmsms)\
**Post date:** [September 4, 2009, 9:47am UTC](https://www.ruby-forum.com/t/strange-nomethoderrors-in-production-mode-i-just-dont-know-what-to-do/174916/5 "2009-09-04T09:47:33Z")

</div>

2009/9/4 ms [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> “.methods()” only contains the default inherited methods. I am  
> absolutely confused.

I presume that we are talking about the same server hardware running  
in production vs development mode here? Are you using the same server  
s/w? Webrick or whatever.

I believe the differences between the two modes are purely the  
differences between production.rb and development.rb in  
config/environments (config.action\_controller.perform\_caching and so  
on). Have you modified one of these away from the default?

If not then you could change the contents of production.rb to be the  
same as development.rb and then iteratively change it back till you  
find the trigger that makes it fail. This may give a clue.

Colin

---

<div class="post-metadata">

**Author:** ![msmsms](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/34f0e0/32.png) [@msmsms](https://www.ruby-forum.com/u/msmsms)\
**Post date:** [September 4, 2009, 10:44am UTC](https://www.ruby-forum.com/t/strange-nomethoderrors-in-production-mode-i-just-dont-know-what-to-do/174916/6 "2009-09-04T10:44:56Z")

</div>

2009/9/4 ms [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> to false, I face the problems described. But development with  
> config.action\_controller.perform\_caching set to true does not reload  
> the source code after a new request, so I have to restart the server  
> every time I make changes to the source.

Sorry I am not quite getting that. You say ‘As you mentioned, the  
config.action\_controller.perform\_caching ist the problem. If it is set  
to false, I face the problems described’. So you get the problem when  
caching is set to false? But that is the development mode.

Colin

---

<div class="post-metadata">

**Author:** ![msmsms](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/34f0e0/32.png) [@msmsms](https://www.ruby-forum.com/u/msmsms)\
**Post date:** [September 4, 2009, 10:59am UTC](https://www.ruby-forum.com/t/strange-nomethoderrors-in-production-mode-i-just-dont-know-what-to-do/174916/7 "2009-09-04T10:59:00Z")

</div>

Hi,

omg, that helped, thank you! 🙂 In one model, I did two ‘requires’. I  
changed them to ‘require\_dependency’ and that works for me now. The  
only question I asked myself is, why I have to do ‘require’ there. I  
just commented these lines with: “Just a workaround. Somehow rails  
does not autoload these classes.” I just removed the ‘requires’  
completely, but then some classes are not autoloaded. I need to do a  
‘require\_dependeny’. How does this come since rails normally autoloads  
all classes?

Thanks again,  
ms

---

<div class="post-metadata">

**Author:** ![msmsms](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/34f0e0/32.png) [@msmsms](https://www.ruby-forum.com/u/msmsms)\
**Post date:** [September 4, 2009, 10:45am UTC](https://www.ruby-forum.com/t/strange-nomethoderrors-in-production-mode-i-just-dont-know-what-to-do/174916/8 "2009-09-04T10:45:31Z")

</div>

On Sep 4, 9:36 am, ms [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> config.action\_controller.perform\_caching set to true does not reload  
> the source code after a new request, so I have to restart the server  
> every time I make changes to the source.

If class caching (or rather the absence thereof) is causing the  
problem it is usually a sign that you are confusing the dependencies  
system. One way of doing this is to use require to require classes  
that are part of your application - you should need to do this at all  
since rails will load the classes for you (use require\_dependency if  
you have to)

> Then I tried the following: I extracted my methods and put them into a  
> module. I included this module and suddenly those methods I extracted  
> were existent again, also after a few reloads. But still, the  
> association proxy methods are missing. I can’t explain this to me.

I wouldn’t spend time on looking for workaround like this - you will  
probably just confuse the issue.

Fred
