Plugin conflict: helper method included by one plugin seems to disappear when another plugin is present
Added by Mayama Takeshi over 2 years ago
I'm using the "CoreHelper.send(:include, MyHelper)" call mentioned in:
https://www.redmine.org/issues/11151#change-104998
in my plugin:
https://github.com/MayamaTakeshi/redmine_rt/blob/7872c77c9a776f227f22bea659432f367cbf4dd6/init.rb
to add one extra helper method named issue_history_tabs_for_redmine_rt for the issue view:
https://github.com/MayamaTakeshi/redmine_rt/blob/7872c77c9a776f227f22bea659432f367cbf4dd6/lib/redmine_rt/issues_helper_patch.rb
This works fine.
However, if I add some other plugin like this one:
https://github.com/berti92/mega_calendar
the method issue_history_tabs_for_redmine_rt disappears:
Rendered plugins/mega_calendar/app/views/issues/show.html.erb (500.0ms)
Rendered plugins/redmine_rt/app/views/issues/show.html.erb within layouts/base
(531.5ms)
Completed 500 Internal Server Error in 1810ms (ActiveRecord: 38.2ms)
ActionView::Template::Error (undefined local variable or method `issue_history_tabs_for_redmine_rt' for #<#<Class:0x00007f009593f048>:0x00007f0095923c80>
Did you mean? issue_history_tabs):
220:
221: " >
222: <div id="history" data-comment_sorting="<=
User.current.wants_comments_in_reverse_order? ? 'desc' : 'asc' >">
223: <= render_tabs issue_history_tabs_for_redmine_rt, issue_history_default_tab >
224: </div>
225: < end %>
226:
plugins/mega_calendar/app/views/issues/show.html.erb:223:in `_f5cbbf994aa425d63b91d5e401824cee'
plugins/redmine_rt/app/views/issues/show.html.erb:16:in `_c00189960b682643e9d63aa83fe5fe78'
app/controllers/issues_controller.rb:112:in `block (2 levels) in show'
app/controllers/issues_controller.rb:104:in `show'
lib/redmine/sudo_mode.rb:61:in `sudo_mode'
I checked the code for the mega_calendar plugin but could not find what would be causing this (I was thinking maybe it patches the IssuesHelper too but it doesn't).
The same happens if I remove mega_calendar and add:
https://www.redmine.org/plugins/redmineup_tags
Does anyone have any clue about what would be causing this?
Replies (3)
RE: Plugin conflict: helper method included by one plugin seems to disappear when another plugin is present
-
Added by Mayama Takeshi over 2 years ago
Doing some tests I realized the problem happens because the other plugin also patches IssuesController.
The patch for this controller can even be blank like this:
require_dependency 'issues_controller' module MegaCalendar module IssuesControllerPatch end end
and it is enough for the plugin to do this in its init.rb file:
require_dependency 'mega_calendar/issues_controller_patch'
for the problem to happen.
It is not necessary to do:
IssuesController.send(:prepend, MegaCalendar::IssuesControllerPatch)
So there is some rails magic at play here maybe based on the Patch suffix and it seems the IssuesHelper module is reset.
But, I realized I don't need to patch IssuesHelper and instead I just moved the method issue_history_tabs_for_redmine_rt from IssuesHelperPatch to my IssuesControllerPatch.
And after that the problem stopped happening (ref: https://github.com/MayamaTakeshi/redmine_rt/issues/5).
Anyway, I'll be glad to hear if someone can explain this behavior (I am not a rails/ruby dev by trade).
RE: Plugin conflict: helper method included by one plugin seems to disappear when another plugin is present
-
Added by Jens Krämer over 1 year ago
There is no magic involved relating to the module name, it's because of the way how helper methods declared in controllers are made available to views in Rails.
- mega_calendar isloaded before your plugin (due to it's name which comes before your plugin when sorted alphabetically
- require_dependency 'issues_controller
in mega_calendar will cause IssuesController to be loaded. At this point, the view helpers available in issue views are loaded as well. Any later modifications of existing helper modules by your plugin are at risk to be ineffective. I write at risk because some modifications, like method aliasing, are still possible. But prepend, for example, will not work.
One solution to this problem is to not try to patch existing helper modules, but instead declare your own helper module and call helper :your_plugin_helper
in your issue controller patch. I outlined that approach a while ago here: https://jkraemer.net/2018/05/add-a-project-settings-tab-for-your-redmine-plugin/
RE: Plugin conflict: helper method included by one plugin seems to disappear when another plugin is present
-
Added by Mayama Takeshi over 1 year ago
Nice article.
Thanks a lot.