Plugins 在扩展控制器中添加现有帮助器(Redmine插件开发)

Plugins 在扩展控制器中添加现有帮助器(Redmine插件开发),plugins,helper,redmine,redmine-plugins,Plugins,Helper,Redmine,Redmine Plugins,任何人都可以指导我通过正确的方法将现有帮助程序添加到以前不包含此帮助程序的扩展控制器中 例如,我在timelog\u controller\u patch.rb中扩展了timelog\u controller.rb控制器。然后,我尝试添加助手查询,这带来了一些我想在补丁中使用的功能 如果在修补程序(我的timelog扩展控件)中添加帮助程序,我总是会收到相同的错误: 错误:未初始化的常量Rails::Plugin::TimelogControllerPatch(NameError) 以下是我如何

任何人都可以指导我通过正确的方法将现有帮助程序添加到以前不包含此帮助程序的扩展控制器中

例如,我在timelog\u controller\u patch.rb中扩展了timelog\u controller.rb控制器。然后,我尝试添加助手查询,这带来了一些我想在补丁中使用的功能

如果在修补程序(我的timelog扩展控件)中添加帮助程序,我总是会收到相同的错误:

错误:未初始化的常量Rails::Plugin::TimelogControllerPatch(NameError)

以下是我如何做到的一个例子:

module TimelogControllerPatch       
    def self.included(base)
        base.send(:include, InstanceMethods)
        base.class_eval do
          alias_method_chain :index, :filters
        end
    end
    module InstanceMethods
        # Here, I include helper like this (I've noticed how the other controllers do it)
        helper :queries
        include QueriesHelper

        def index_with_filters
            # ...
            # do stuff
            # ...
        end
    end # module
end # module patch
但是,当我在原始控制器中包含同一个助手时,一切正常(当然,这不是正确的方法)

有人能告诉我我做错了什么吗


提前感谢:)

需要对控制器的类调用
helper
方法,将其放入一个模块中,但该模块无法正确运行。这将有助于:

module TimelogControllerPatch       
    def self.included(base)
        base.send(:include, InstanceMethods)
        base.class_eval do
          alias_method_chain :index, :filters
          # 
          # Anything you type in here is just like typing directly in the core
          # source files and will be run when the controller class is loaded.
          # 
          helper :queries
          include QueriesHelper

        end
    end
    module InstanceMethods
        def index_with_filters
            # ...
            # do stuff
            # ...
        end
    end # module
end # module patch
请在Github上随意查看我的任何插件,我的大部分补丁都在
lib/plugin\u name/patches
中。我知道我有一个在那里添加了助手,但我现在找不到它

另外,别忘了也需要你的补丁。如果它不在插件的
lib
目录中,请使用相对路径


Eric Davis

或者,如果您不想使用修补程序:

Rails.configuration.to_prepare do
  TimelogController.send(:helper, :queries)
end

谢谢它就像一个符咒!不幸的是,文档非常稀少,我无法找到解决这个问题的好方法。非常感谢。这是一个很好的测试解决方案,但据我所知,它仅用于开发目的。尽管如此,在测试概念验证之前,这是一种快速而好的方法。