Rails 3. How to add a helper that ActiveAdmin will use? Rails 3. How to add a helper that ActiveAdmin will use? ruby ruby

Rails 3. How to add a helper that ActiveAdmin will use?


You can define them in app/helpers/ as you tried but you need to include them trough the active admin's initializer like this:

# in config/initializers/active_admin.rbActiveAdmin.setup do |config|    ....endmodule ActiveAdmin::ViewHelpers  include ApplicationHelperend


You need to put your helper functions in app/helpers/active_admin/views_helper.rb file Example:

module ActiveAdmin::ViewsHelper #camelized file name  def my_helper        # do something   end end 


What I have found using ActiveAdmin 0.6.1 is that ActiveAdmin will look for helpers in app/helpers/active_admin/*_helper.rb, but the name doesn't really matter.

What does matter is:

  1. the filename must end in "_helper.rb"
  2. the module name must be the camel-case of the file name
  3. the file must be in app/helpers/active_admin/ directory.

If anyone knows where this is officially documented, that would be awesome.

Here is an example: https://gist.github.com/afred/7035a657e8ec5ec08d3b