Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can ActiveAdmin load javascript bundled by webpack? - Rails 5.1

I've upgraded from rails 4.2.6 to rails 5.1, and then started to use webpack.
All set up for using webpack have done, but I can't figure out how to load javascript files on the ActiveAdmin page.
ActiveAdmin loads app/assets/javascripts/active_admin.js.coffee by default.
Is there a way to load javascript files which is bundled by webpack on the ActiveAdmin page?

like image 730
ggtmtmgg Avatar asked Jun 30 '17 06:06

ggtmtmgg


1 Answers

I'm a bit late, but I believe it's better to wrap the method rather than to completely override the class. Also, monkey patching Header will result in tags being rendered in div with id="header". In order to render them in <head /> I did the following:

ActiveAdmin::Views::Pages::Base.class_eval do
  alias_method :original_build_active_admin_head, :build_active_admin_head

  def build_active_admin_head(*args, &block)
    original_build_active_admin_head(*args, &block)
    within @head do render '/custom_headers' end
  end
end

Put this file to config/initializers (so that it won't be reloaded every time in development mode resulting in infinite loop) folder and create a app/views/_custom_headers.html.erb file with whatever you need.

like image 172
alexb Avatar answered Sep 22 '22 17:09

alexb