我开发了两个插件,它们都修改了同一个类的相同alias_method_chain
方法,结果导致堆栈级别太深错误。
第一个插件:
Rails.configuration.to_prepare do
require 'issue_patch'
Issue.send :include, IssuePatch
end
module IssuePatch
module InstanceMethods
def editable_custom_field_values_with_sort(user=nil)
editable_custom_field_values_without_sort(user).sort
end
end
def self.included(receiver)
receiver.send :include, InstanceMethods
receiver.class_eval do
alias_method_chain :editable_custom_field_values, :sort
end
end
end
第二个插件以相同的方式修改类,但具有不同的功能:
Rails.configuration.to_prepare do
require 'issue_patch'
Issue.send :include, IssuePatch
end
module IssuePatch
module InstanceMethods
def editable_custom_field_values_with_some_stuff(user=nil)
editable_custom_field_values_without_some_stuff(user).select { |c| c.have_stuff? }
end
end
def self.included(receiver)
receiver.send :include, InstanceMethods
receiver.class_eval do
alias_method_chain :editable_custom_field_values, :some_stuff
end
end
end
当我尝试调用此方法时,我得到:
ActionView::Template::Error (stack level too deep):
plugins/my_plugin/lib/issue_patch.rb:8
一个可能但破解的解决方案是使用第一个插件功能对 redmine 代码进行简单的猴子补丁,以便第二个插件可以为它起别名而不会出现任何错误。
那么我该如何解决这个错误呢?