以前はこのヘルパーが含まれていなかった拡張コントローラーに既存のヘルパーを追加する正しい方法を誰かが案内してくれますか?
たとえば、 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
ただし、元のコントローラーに同じヘルパーを含めると、すべて正常に動作します (もちろん、これは正しい方法ではありません)。
誰かが私が間違っていることを教えてもらえますか?
前もって感謝します :)