eucalypt
Search…
Helpers
Helpers modules contain methods that can be used in controllers and views.

CLI tasks

Example

1
module ProductHelper
2
def quantity(product)
3
String.build do |s|
4
s << product.quantity.to_s
5
s << " "
6
s << product.pluralize(product.quantity, product.name)
7
s << " remaining."
8
end
9
end
10
11
def name(product)
12
product.name.titleize
13
end
14
end
Copied!
    The quantity and name helper methods will only be accessible within the ProductController class and any views rendered from that class.

Application helper

The application helper works slightly differently. The application helper is included in the ApplicationController class.
Since ApplicationController is inherited from every new controller, every controller (and view) has access to helper methods defined in the application helper.
Methods should only be defined in this module if you want them accessible from all parts of your application.
Last modified 3yr ago