|# ...rest of the initializer here...|
|# you can move the call to super at the end, if you wish|
|# to insert things at the begining of the page|
|# this will be added at the end of <body>|
|within @body do|
|render partial: '...'|
|# this will be added at the end of <head>|
|within @head do|
|ActiveAdmin::Views::Pages::Base.send :prepend, AdminPageLayoutOverride|
Ditto - total lifesaver! However, On ActiveAdmin 1.2.1, this gives an error:
You'll have to prepend to #build_active_admin_head and #build_body instead of directly to #build.
In my use case, I wanted to prepend a partial BEFORE the ActiveAdmin masthead/page header, so I did this:
Here's the relevant class we're patching:
If you're on another version of the gem, you can look at the version from that branch to figure out your exact patching strategy.
Thanks all! This was helpful.
In Active Admin 1.4.3, it's like this:
module AdminPageLayoutOverride def build_page(*args) within body(class: body_classes) do render partial: 'layouts/global/environment_banner' end super end end ActiveAdmin::Views::Pages::Base.send :prepend, AdminPageLayoutOverride
Is there a way to do this now in AA 2.7?
This approach gives me:
Actually, answered this myself based upon the source: just replace
This worked for me in AA 2.2. But I noticed that it adds two head tags. Any clue on how to fix it?
LOL - I just looked at the HTML in AA 2.7, and found the JS and CSS tags in the
It works correctly if you put the
module AdminPageLayoutOverride def build(*args) # This will be added at the beginning of <head> within head do # stuff here end # This will be added at the beginning of <body> # within body do # end super end end ActiveAdmin::Views::Pages::Base.prepend(AdminPageLayoutOverride)
That being said, I think the recommended way to do this now is via the
If you don't have that section (I didn't), then assuming your codebase is in a repo, you can rerun the AA generator to get the updated initializer, skipping everything you can except the initializer generation, reverting everything except the initializer changes, and then using the diff to decide what to revert in the initializer. (There may be a better procedure than that, but that does work.)