作者:拍友2502876287 | 来源:互联网 | 2023-09-25 17:51
Iwanttooverridethehelpermethodwithmyplugin.Itriedtocreateanewhelpermodulewithmeth
I want to override the helper method with my plugin. I tried to create a new helper module with method that should override like this:
我想用我的插件覆盖helper方法。我试图创建一个新的辅助模块,其方法应该覆盖如下:
myplugin/app/helpers/issues_helper.rb
module IssuesHelper
def render_custom_fields_rows(issus)
'it works!'.html_safe
end
end
But this doesn't work. Core method still used in appropriate view.
但这不起作用。核心方法仍在适当的视图中使用。
Hack solution:
Hack解决方案:
issues_helper_patch.rb
module IssuesHelperPatch
def self.included(receiver)
receiver.send :include, InstanceMethods
receiver.class_eval do
def render_custom_fields_rows(issue)
"It works".html_safe
end
end
end
end
init.rb
Rails.configuration.to_prepare do
require 'issues_helper_patch'
IssuesHelper.send :include, IssuesHelperPatch
end
This is the hack because in normal way methods should be in InstanceMethods
module of IssuesHelperPatch
module.
这是hack,因为正常方式的方法应该在IssuesHelperPatch模块的InstanceMethods模块中。
2 个解决方案