Project

General

Profile

Plugin not loaded when server starts [but loaded fine in script/console and tests]

Added by Adam Walters about 15 years ago

Hello,

I'm writing a plugin and having some issues getting it to work in when the server is actually running. When i go into the console, i'm 100% sure my plugin is loaded, as i can call the newly included methods added onto Issues. However, these methods are not present when the server is actually running and displaying pages. Is there some reason why these two should be inconsistent?

I followed the plugin pattern used here: http://github.com/edavis10/redmine_rate/blob/4666ddb10e1061ca3ef362735d0d264676b99024/lib/rate_users_helper_patch.rb
as instructed by the plugin developer wiki.

This is all occurring within the development environment

Redmine version: 0.8.0.devel1858
About your application's environment
Ruby version 1.8.7 (i686-darwin9.4.0)
RubyGems version 1.3.1
Rails version 2.2.2
Active Record version 2.2.2
Action Pack version 2.2.2
Active Resource version 2.2.2
Action Mailer version 2.2.2
Active Support version 2.2.2
Edge Rails revision unknown
Application root /Users/tukaiz/Development/rails/repos/redmine/trunk
Environment development
Database adapter mysql
Database schema version 20090318181151

Thanks in advance!
Adam


Replies (3)

RE: Plugin not loaded when server starts [but loaded fine in script/console and tests] - Added by Adam Walters about 15 years ago

I little more testing and i believe i'm on the correct path. Somehow the module i include into Issue.rb is being removed. If i restart the server, the first request DOES show that my module is in fact included, and my plugin code runs. However, ALL subsequent requests DO NOT have my plugin mixed into the Issue object. Why would this be disappearing?

RE: Plugin not loaded when server starts [but loaded fine in script/console and tests] - Added by Eric Davis about 15 years ago

It's because in development mode, Rails unloads all of it's classes in the application (e.g. Issue) after each request but not in plugins. On the second request, the plugin is patching the old class which isn't around anymore so you don't see your changes. To work around this, wrap all your include calls in Dispatcher.to_prepare

http://www.redmine.org/boards/3/topics/4070#message-4797

I'm going to be updating my plugins and writing about this soon

Eric

RE: Plugin not loaded when server starts [but loaded fine in script/console and tests] - Added by Eric Davis about 15 years ago

Adam (and anyone else):

I've written a blog post that outlines the Dispatcher.to_prepare in more detail. You might find it useful.

http://theadmin.org/articles/2009/4/13/how-to-modify-core-redmine-classes-from-a-plugin

Eric

    (1-3/3)