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

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! :slight_smile:

I am really thankful for any hint!

Cheers,
ms

make sure the production application was restarted correctly!

(it happened to me… )

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

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

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.

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

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.

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

Hi,

omg, that helped, thank you! :slight_smile: 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