Pergunta

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 !

Foi útil?

Solução

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
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top