我想用我的插件覆盖辅助方法。我试图创建一个新的辅助模块,其方法应该像这样覆盖:
myplugin/app/helpers/issues_helper.rb
module IssuesHelper
def render_custom_fields_rows(issus)
'it works!'.html_safe
end
end
但这不起作用。核心方法仍然在适当的视图中使用。
破解解决方案:
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
这是 hack,因为在正常情况下,方法应该在InstanceMethods
模块的IssuesHelperPatch
模块中。