method works only once just fresh after restart. Later it says ActionView::Template::Error (undefined method

Added by Andrzej Nowak over 4 years ago

I am trying to create a plugin.
I have a helper with methods, and a view where I am using those methods.
After redmine restart (touch tmp/restart.txt) - my view shows perfectly and methods work. But when I refresh again (or open another similar page) - redmine says:
ActionView::Template::Error (undefined method `[my-method-name]' for #<#<Class:0xb31a64dc>:0xb31a4344>):

Do I have to use some sort of "clean releasing of resources" or something? Why it works well just one time after restart, but then - does not.

Anyone any clues?

Replies (2)

RE: method works only once just fresh after restart. Later it says ActionView::Template::Error (undefined method - Added by Andrzej Nowak over 4 years ago

I have found a solution for this problem. Create a file
tmp/always_restart.txt so you don't have to restart manually (or by touching tmp/restart.txt before every request)

I assume this is not the right way of doing things, but it works.

Additional info: I added some puts in different places of my plugin's helper file (plugin/mypluginname/app/helper/timeloghelperpatch.rb), init.rb, and standard timelog_helper.rb file. After fresh restart - I see that all puts are shown in /var/log/apache2/error.log. But on second request (like page refresh or opening other page) - it shows only puts from standard application app/helpers/timelog_helper.rb , but it does not show puts from myplugin's init.rb, neither my helper file.
Maybe it is something like caching of files, because in log/production.log I see that error is in something like
undefined method `testukas' for #<#<Class:0xb5a81f0>:0xb588120> -but I don't have such class 0xb5a81f0 neither 0xb588120
...
plugins/mypluginname/app/views/timelog/new.html.erb:11:in `_plugins_mypluginname_app_views_timelog_new_html_erb___531623980_95167960' - there is also no such file. Looks like such file is created automatically (caching?)

In my configuration config/environments/production.rb I have all caching disabled (at least what I found on the net about cache disabling):

config.cache_classes = false
config.eager_load = false
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_mailer.raise_delivery_errors = false
config.action_mailer.logger = nil
config.active_support.deprecation = :log
config.assets.debug = true
config.reload_classes_only_on_change = false
config.assets.compress = false
config.server_static_assets = false

(PS. yes, I use production env, because I have absolutely separate application for testing, so I don't need to run development environment.)

But non of this worked until I created tmp/always_restart.txt

Any suggestions? Or am I missing something very basic? Maybe about overwriting a standard view in a plugin and using custom functions from custom model in custom helper of this plugin? (Helper is required in init.rb of myplugin)

RE: method works only once just fresh after restart. Later it says ActionView::Template::Error (undefined method - Added by Andrzej Nowak over 4 years ago

It looks like I have found a solution.
In my plugin's init.rb, beside a line

require '/pathtoplugins/pluginname/helpers/timeloghelperpatch'

I added another one:
include TimelogHelperPatch

and it seems that it started working - does not require restart before each request.

PS. I found a text which helped me a lot:

I am calling "load" so it actually reloads the file, whereas "require" would just check if it has been loaded and determine it already has so it will not reload it. (I just threw > this together and don't use it, but Ruby is extremely flexible and will allow you to do quite a bit.) Use something like this wisely and only in a dev environment.

on page https://stackoverflow.com/questions/5308970/why-does-code-need-to-be-reloaded-in-rails-3/15941616

(1-2/2)