module ActionController::Helpers::ClassMethods
Public Instance Methods
# File actionpack/lib/action_controller/metal/helpers.rb, line 101 def all_helpers_from_path(path) helpers = Array(path).flat_map do |_path| names = Dir["#{_path}/**/*_helper.rb"].map { |file| file[_path.to_s.size + 1..-"_helper.rb".size - 1] } names.sort! end helpers.uniq! helpers end
Returns a list of helper names in a given path.
ActionController::Base.all_helpers_from_path 'app/helpers' # => ["application", "chart", "rubygems"]
# File actionpack/lib/action_controller/metal/helpers.rb, line 71 def helper_attr(*attrs) attrs.flatten.each { |attr| helper_method(attr, "#{attr}=") } end
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 actionpack/lib/action_controller/metal/helpers.rb, line 76 def helpers @helper_proxy ||= begin proxy = ActionView::Base.empty proxy.config = config.inheritable_copy proxy.extend(_helpers) end end
Provides a proxy to access helper methods from outside the view.
# File actionpack/lib/action_controller/metal/helpers.rb, line 92 def modules_for_helpers(args) args += all_application_helpers if args.delete(:all) super(args) end
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
© 2004–2019 David Heinemeier Hansson
Licensed under the MIT License.