Methods
Public Instance methods
helper(*args, &block)

Declare a helper:

  helper :foo

requires ‘foo_helper’ and includes FooHelper in the template class.

  helper FooHelper

includes FooHelper in the template class.

  helper { def foo() "#{bar} is the very best" end }

evaluates the block in the template class, adding method foo.

  helper(:three, BlindHelper) { def mice() 'mice' end }

does all three.

    # File lib/action_mailer/helpers.rb, line 40
40:       def helper(*args, &block)
41:         args.flatten.each do |arg|
42:           case arg
43:             when Module
44:               add_template_helper(arg)
45:             when String, Symbol
46:               file_name  = arg.to_s.underscore + '_helper'
47:               class_name = file_name.camelize
48: 
49:               begin
50:                 require_dependency(file_name)
51:               rescue LoadError => load_error
52:                 requiree = / -- (.*?)(\.rb)?$/.match(load_error.message).to_a[1]
53:                 msg = (requiree == file_name) ? "Missing helper file helpers/#{file_name}.rb" : "Can't load file: #{requiree}"
54:                 raise LoadError.new(msg).copy_blame!(load_error)
55:               end
56: 
57:               add_template_helper(class_name.constantize)
58:             else
59:               raise ArgumentError, 'helper expects String, Symbol, or Module argument'
60:           end
61:         end
62: 
63:         # Evaluate block in template class if given.
64:         master_helper_module.module_eval(&block) if block_given?
65:       end
helper_attr(*attrs)

Declare a controller attribute as a helper. For example,

  helper_attr :name
  attr_accessor :name

makes the name and name= controller methods available in the view. The is a convenience wrapper for helper_method.

    # File lib/action_mailer/helpers.rb, line 87
87:       def helper_attr(*attrs)
88:         attrs.flatten.each { |attr| helper_method(attr, "#{attr}=") }
89:       end
helper_method(*methods)

Declare a controller method as a helper. For example,

  helper_method :link_to
  def link_to(name, options) ... end

makes the link_to controller method available in the view.

    # File lib/action_mailer/helpers.rb, line 71
71:       def helper_method(*methods)
72:         methods.flatten.each do |method|
73:           master_helper_module.module_eval "def \#{method}(*args, &block)\ncontroller.send!(%(\#{method}), *args, &block)\nend\n"
74:         end
75:       end