Forums » Development »
[Plugins] Strange bug with plugin load ordering
Added by Alex A over 13 years ago
I developing two plugins thats patch some redmine classes. First plugin is redmine_repository plugin, it is patching RepositoryController. Second plugin is redmine_sidebar plugin, that patching ApplicationHelper. The patching like this
module RepositoriesControllerPatch def self.included(base) # :nodoc: base.extend(ClassMethods) base.send(:include, InstanceMethods) end module ClassMethods end module InstanceMethods # there is some methods end end RepositoriesController.send(:include, RepositoriesControllerPatch)
module SidebarApplicationHelperPatch def self.included(base) # :nodoc: base.extend(ClassMethods) base.send(:include, InstanceMethods) end module ClassMethods end module InstanceMethods # there is some methods end end ApplicationHelper.send(:include, SidebarApplicationHelperPatch)
In default plugins load in ordering: redmine_repository is first, redmine_sidebar is second. In this case the error occured
undefined method `show_sidebar?' for #<ActionView::Base:0x7fcbd8d91128>
but
show_sidebar?
method is defined in SidebarApplicationHelperPatch.If i insert into
enviroment.rb
plugin loading orderconfig.plugins = [ :all, :redmine_sidebar, :redmine_repository ]
there is no error occured.
Why? Can someone explain me because of what is happening?
Replies (1)
RE: [Plugins] Strange bug with plugin load ordering - Added by Felix Schäfer over 13 years ago
If redmine_repository
is loaded first, the RepositoriesController
is already instantiated when redmine_sidebar
is loaded, and thus the patching of ApplicationHelper
doesn't get passed to RepositoriesController
.
One solution we use against this is:
ApplicationController.subclasses.each do |subclass|
Kernel.const_get(subclass).send(:include, SomePlugin::ApplicationControllerPatch)
end
Not sure how good that would work with the ApplicationHelper
, but you get the idea.