0

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:

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:

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.

4

2 に答える 2

3
IssuesHelper.class_eval do
  def render_custom_fields_rows(issus)
    'it works!'.html_safe
  end
end
于 2013-05-31T21:07:54.870 に答える
0

これは、この問題に対する私見の良い解決策です。

issues_helper_patch.rb
module IssuesHelperPatch
  module InstanceMethods
    def render_custom_fields_rows_with_message(issue)
      "It works".html_safe
    end
  end

  def self.included(receiver)
    receiver.send :include, InstanceMethods

    receiver.class_eval do
      alias_method_chain :render_custom_fields_rows, :message
    end
  end
end

init.rb

Rails.configuration.to_prepare do
  require 'issues_helper_patch'
  IssuesHelper.send     :include, IssuesHelperPatch
end
于 2013-06-02T18:39:18.587 に答える