helper_method
is straightforward: it makes some or all of the controller's methods available to the view.
What is helper
? Is it the other way around, i.e., it imports helper methods into a file or a module? (Maybe the name helper
and helper_method
are alike. They may rather instead be share_methods_with_view
and import_methods_from_view
)
The method
helper_method
is to explicitly share some methods defined in the controller to make them available for the view. This is used for any method that you need to access from both controllers and helpers/views (standard helper methods are not available in controllers). e.g. common use case:the
helper
method on the other hand, is for importing an entire helper to the views provided by the controller (and it's inherited controllers). What this means is doingFor Rails > 3.1
makes all helper modules available to all views (at least for all controllers inheriting from application_controller.
makes the UserHelper methods available to views for actions of the home controller. This is equivalent to doing: