Your App’s Helpers in Administrate

If you’re using Administrate (a wonderful Rails engine produced by the folks at thoughtbot) you may have found that your application’s helpers are not available to Administrate’s views.

Exposing your app’s helper methods to Administrate is pretty straight forward — just add the following to your application.rb:

# config/application.rb
module YourApp
  class Application < Rails::Application
    # ... your application's config

    # Load App helpers into administrate
    config.to_prepare do
      Administrate::ApplicationController.helper YourApp::Application.helpers
    end
  end
end

If you’re interested in how this works take a look at this bit of the Rails source code.

Rails’ AbstractController provides a method (specifically modules_for_helpers) for submitting a list of helpers which are processed and added into the engine.  Very cool!

The nice thing here is that is not specific to Administrate and can be used with any Rails engine needing access to your application’s helpers.