I would like to do some analytics on my active admin enabled rails application. For that, I need to paste some <script> and <noscript> code just before the </body> tag in my layout file. Unfortunately, I am not able to do that as the application.html layout file seems ineffective since ActiveAdmin renders its own layout files.
Is there a hook/place where I can insert the custom html code ?
Alright, first thing you’ll have to clone the repository into your rails app, usually you’d put it in the vendor directory but rails throws this annoying warning that it will deprecate the use of the vendor directory style dir, it doesn’t matter much if you’re going to production with a 3.* version, so just do this into either vendor or lib directory in your rails app.
git clone git://github.com/gregbell/active_admin.gitNow change your
Gemfileand have the gem loaded from the directory you setgem 'activeadmin', :path => 'lib/activeadmin'Now you have your own version of activeadmin, so whatever you need to edit you can do it directly from that dir, including changing the default layout that it is bundled with.
Few words of advise:
Although this method allows you to far more customize active admin you are fully aware that to update it to a newer version would need you to do some
git pulling and merging if necessary.I used this method with jquery-ui-rails plugin and with another gem, it works splendid and moreover you can contribute to the gem back if you add the hook you wanted to the gem itself.
Good luck!
—- Edit —-
As you pointed out in a comment activeadmin doesn’t work exactly how you would expect but no worries it’s still an easy fix.
Under the hood activeadmin uses something called
arbrewhich is created and maintained by the same developer.https://github.com/gregbell/arbre, it’s just aDOMlibrary for ruby.So what you have to do is this:
Head over to this file inside the activeadmin dir you just cloned
lib/active_admin/views/footer.rbthis is the footer of the activeadmin application, as you can see inside the
buildmethod you can insert inside something such asadd_scriptsmethod and below addI am not fully sure how the
arbresyntax flows but it shouldn’t be hard to figure out.Good luck!