문제

i'm working on refinerycms, trying to add preview feature to news like pages, i'm trying to include my own helper to a controller, 'include' does not works, but 'helper' works.

sample code:

module Refinery
  module News
    module Admin
      class PreviewController < ActionController::Base
        #include LayoutHelper # not ok
        helper LayoutHelper # Ok
      end
    end
  end
end

i've read the api, helper is working like 'require and include', but i don't know the real difference here.

thanks !

도움이 되었습니까?

해결책

helper LayoutHelper does include LayoutHelper, but it is included directly in the template class.

while include LayoutHelper, the module is included in the controller class.

You could check the source of helper:

# File actionpack/lib/abstract_controller/helpers.rb, line 93
def helper(*args, &block)
  modules_for_helpers(args).each do |mod|
    add_template_helper(mod)
  end

  _helpers.module_eval(&block) if block_given?
end
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top