Skip to content

Instantly share code, notes, and snippets.

@michaelgpearce
Last active February 21, 2023 03:58
Show Gist options
  • Save michaelgpearce/21fd8bfde4944f7c9dbabb3957874c62 to your computer and use it in GitHub Desktop.
Save michaelgpearce/21fd8bfde4944f7c9dbabb3957874c62 to your computer and use it in GitHub Desktop.
Active Admin share view helper
# Example:
#
# ActiveAdmin.register Customer do
# add_helper(:header) do |name|
# h1(name)
# end
#
# index do
# helper(:header, 'INDEX')
#
# # ...
# end
#
# show do
# helper(:header, 'SHOW')
#
# # ...
# end
# end
class ActiveAdmin::DSL
def add_helper(name, &block)
config.add_helper(name, block)
end
end
class ActiveAdmin::Views::Pages::Page
def helper(name, *args)
helper_proc = active_admin_config.helpers.fetch(name.to_s)
instance_exec(*args, &helper_proc)
end
end
class ActiveAdmin::Page
def helpers
@helpers ||= {}
end
def add_helper(name, block)
helpers[name.to_s] = block
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment