In Rails, all helpers are included in all views by default.
UsersHelper methods are also available to your
I don’t like having that much stuff in the same namespace. Method names may collide, or else need inelegant prefixes.
This setting makes things more sensible:
ApplicationHelper is still included in all views.
Admin::UsersHelper is only included in
Admin::UsersController views. If that controller inherits from
Admin::BaseHelper will be included as well.
And here’s a nice (and fairly obvious) trick: you can still use regular Ruby modules to organize your methods into more than one file.
For example, I like to have a
LayoutHelper that the application layout template can use:
1 2 3 4 5
1 2 3 4 5 6 7
include_all_helpers off, the
LayoutHelper isn’t automatically included anywhere. But by simply
includeing it in the global
ApplicationHelper, now its methods are global too.
You get the benefits of splitting helpers into multiple files, without the downsides of having every helper available everywhere.