2012-01-09 2 views
2

이 도우미가 이전에는 포함되지 않은 확장 컨트롤러에 기존 도우미를 추가 할 수있는 사람이 있습니까?확장 컨트롤러 (Redmine Plugin Dev)에 기존 도우미 추가

예를 들어, I는 timelog_controller_patch.rbtimelog_controller.rb 컨트롤러를 확장 하였다. 그런 다음 도우미 쿼리을 추가하려고했는데, 이는 내 패치에서 사용하려는 일부 기능을 제공합니다.

내 패치에서 도우미를 추가하는 경우 (내 TimeLog라는 제어 확장), 난 항상 같은 오류 얻을 :

오류 : 초기화되지 않은 상수 레일 :: 플러그 :: 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 

(물론, 이것은 올바른 방법이 아니다) : 여기가했던 방법의 예입니다.

누군가 내가 뭘 잘못하고 있다고 말할 수 있습니까? 사전에

감사합니다 :)

답변

4

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_name/patches에있을 것입니다. 도우미를 추가하는 사람이 있지만 지금은 찾을 수 없다는 것을 알고 있습니다. https://github.com/edavis10

P. 패치를 요구하는 것을 잊지 마십시오. 플러그인의 lib 디렉토리에 없다면 상대 경로를 사용하십시오.

에릭 데이비스

+0

감사합니다! 그것은 매력처럼 작동합니다! 불행히도 설명서는 꽤 희소하고이 문제에 대한 좋은 해결책을 찾을 수 없었습니다. 아주 많이 고마워요. –

0

당신이 패치를하고 싶지 않아요 또는 경우 :

Rails.configuration.to_prepare do 
    TimelogController.send(:helper, :queries) 
end 
관련 문제