谁能指导我通过正确的方式将现有的 Helper 添加到以前不包含此 Helper 的扩展控制器中。
例如,我在 timelog_controller_patch.rb 中扩展了timelog_controller.rb控制器。然后,我尝试添加帮助程序 Queries,它带来了一些我想在我的补丁中使用的功能。
如果我在我的补丁(我的时间日志扩展控件)中添加助手,我总是会得到同样的错误:
错误:未初始化的常量 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
但是,当我在原始控制器中包含相同的助手时,一切正常(当然,这不是正确的方法)。
有人可以告诉我我做错了什么吗?
提前致谢 :)