helper
- 1.0.0 (0)
- 1.1.6 (0)
- 1.2.6 (0)
- 2.0.3 (29)
- 2.1.0 (0)
- 2.2.1 (0)
- 2.3.8 (1)
- 3.0.0
- 3.0.9
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2
- 7.1.3.4
- What's this?
helper(*args, &block)
public
The helper class method can take a series of helper module names, a block, or both.
- *args: One or more Modules, Strings or Symbols, or the special symbol :all.
- &block: A block defining helper methods.
Examples
When the argument is a String or Symbol, the method will provide the "_helper" suffix, require the file and include the module in the template class. The second form illustrates how to include custom helpers when working with namespaced controllers, or other cases where the file containing the helper definition is not in one of Rails' standard load paths:
helper :foo # => requires 'foo_helper' and includes FooHelper helper 'resources/foo' # => requires 'resources/foo_helper' and includes Resources::FooHelper
When the argument is a Module, it will be included directly in the template class.
helper FooHelper # => includes FooHelper
When the argument is the symbol :all, the controller will include all helpers from app/helpers/*/.rb under RAILS_ROOT.
helper :all
Additionally, the helper class method can receive and evaluate a block, making the methods defined available to the template.
# One line helper { def hello() "Hello, world!" end } # Multi-line helper do def foo(bar) "#{bar} is the very best" end end
Finally, all the above styles can be mixed together, and the helper method can be invoked with a mix of symbols, strings, modules and blocks.
helper(:three, BlindHelper) { def mice() 'mice' end }