Module: ActionController::Helpers::ClassMethods

Defined in:
lib/action_controller/metal/helpers.rb

Instance Method Summary collapse

Instance Method Details

#all_helpers_from_path(path) ⇒ Object



95
96
97
98
99
100
101
102
103
104
# File 'lib/action_controller/metal/helpers.rb', line 95

def all_helpers_from_path(path)
  helpers = []
  Array.wrap(path).each do |_path|
    extract  = /^#{Regexp.quote(_path.to_s)}\/?(.*)_helper.rb$/
    helpers += Dir["#{_path}/**/*_helper.rb"].map { |file| file.sub(extract, '\1') }
  end
  helpers.sort!
  helpers.uniq!
  helpers
end

#helper_attr(*attrs) ⇒ Object

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.



73
74
75
# File 'lib/action_controller/metal/helpers.rb', line 73

def helper_attr(*attrs)
  attrs.flatten.each { |attr| helper_method(attr, "#{attr}=") }
end

#helpersObject

Provides a proxy to access helpers methods from outside the view.



78
79
80
# File 'lib/action_controller/metal/helpers.rb', line 78

def helpers
  @helper_proxy ||= ActionView::Base.new.extend(_helpers)
end

#modules_for_helpers(args) ⇒ Object

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.



90
91
92
93
# File 'lib/action_controller/metal/helpers.rb', line 90

def modules_for_helpers(args)
  args += all_application_helpers if args.delete(:all)
  super(args)
end