module ActionController::Helpers::ClassMethods
Public Instance Methods
all_helpers_from_path(path)
click to toggle source
# File lib/action_controller/metal/helpers.rb, line 96 def all_helpers_from_path(path) helpers = Array(path).flat_map do |_path| extract = /^#{Regexp.quote(_path.to_s)}\/?(.*)_helper.rb$/ names = Dir["#{_path}/**/*_helper.rb"].map { |file| file.sub(extract, '\1') } names.sort! end helpers.uniq! helpers end
helper_attr(*attrs)
click to toggle source
Declares helper accessors for controller attributes. For example, the
following adds new name
and name=
instance
methods to a controller and makes them available to the view:
attr_accessor :name helper_attr :name
Parameters¶ ↑
-
attrs
- Names of attributes to be converted into helpers.
# File lib/action_controller/metal/helpers.rb, line 70 def helper_attr(*attrs) attrs.flatten.each { |attr| helper_method(attr, "#{attr}=") } end
helpers()
click to toggle source
Provides a proxy to access helpers methods from outside the view.
# File lib/action_controller/metal/helpers.rb, line 75 def helpers @helper_proxy ||= begin proxy = ActionView::Base.new proxy.config = config.inheritable_copy proxy.extend(_helpers) end end
modules_for_helpers(args)
click to toggle source
Overwrite #modules_for_helpers to accept :all as argument, which loads all helpers in helpers_path.
Parameters¶ ↑
-
args
- A list of helpers
Returns¶ ↑
-
array
- A normalized list of modules for the list of helpers provided.
Calls superclass method
# File lib/action_controller/metal/helpers.rb, line 91 def modules_for_helpers(args) args += all_application_helpers if args.delete(:all) super(args) end
Private Instance Methods
all_application_helpers()
click to toggle source
Extract helper names from files in app/helpers /*_helper.rb
# File lib/action_controller/metal/helpers.rb, line 108 def all_application_helpers all_helpers_from_path(helpers_path) end