If you’ve any sort of organizational sense to you at all chances are you’ve got quite a few helpers tucked in your app/helpers directory (not the stock ones that go one-to-one with your controllers, but other custom ones you’ve written to handle various other common tasks). If so, your application controller probably also has quite a few helper statements to make them available:
1 2 3 4 5 6 7 |
class ApplicationController < ActionController::Base # Our many helpers that need to be available throughout the app [:formatting, :highlighting, :i18n].each { |h| helper h } ... end |
We’ve now got a convenient way to bulk include our helpers.
1 2 3 4 5 6 7 |
class ApplicationController < ActionController::Base # Make all helpers in app/helpers/**/ available helper :all ... end |
Update: Feb. 26th: I previously thought you had to have helper sub-directories to get them properly loaded, but DHH has corrected me. Any and all helpers in your helper directories will get pulled in
And to top things off this is now the default behavior – meaning that all helpers in your helpers directory are automatically included for you. (Hey – you wanted opinionated software)
tags: rubyonrails, rails

You don’t need sub-directories. */.rb will match the current directory too. I actually don’t use sub-directories at all. This was mostly added to accomodate people using nested controllers.
DHH: My bad – you guys have kept me too busy recently – had a momentary lapse.
If
is run by default in the AppController, how is calling useful if OtherHelper is already included?Dr Nic – I don’t think it is. Basically you can do away with the need to call
helperanything.Since all controllers inherit from ApplicationController does this mean all controller’s views now have access to all helper methods even if they are defined in some other controller’s helper?
Why is this considered more desirable?