Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example using of ActiveAdmin helpers

What matters 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.

the first helper:

# app/helpers/active_admin/foo_helper.rb
module ActiveAdmin::FooHelper
  def foo
    "i pity the foo!!!"
  end
end

the second helper:

# app/helpers/active_admin/bar_helper.rb
module ActiveAdmin::BarHelper
  def bar
    "i raise the bar!!!"
  end
end

and methods from both are available in view methods across models like so:

# app/admin/users.rb
ActiveAdmin.register User do
  #...
  show do |user|
    row "Test Both Helper" do |user|
      # both helper methods work here
      foo
      bar
    end
  end
  #...
end

and in the view method for a different model...

# app/admin/company.rb
ActiveAdmin.register Company do
  # ...
  show do |company|
    row "Test Both Helpers" do |company|
      # both helper methods available here too
      foo
      bar
    end
  end
  # ...
end
@IslamAzab

This comment has been minimized.

Copy link

@IslamAzab IslamAzab commented Sep 2, 2014

Should the helper be required or something?

I can not use the 'panel' helper.

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment