-
-
Save francois-ferrandis/1dc749262e7376e62074f908ee70356b to your computer and use it in GitHub Desktop.
# config/initializers/active_admin.rb | |
# ...rest of the initializer here... | |
module AdminPageLayoutOverride | |
def build(*args) | |
# you can move the call to super at the end, if you wish | |
# to insert things at the begining of the page | |
super | |
# this will be added at the end of <body> | |
within @body do | |
render partial: '...' | |
end | |
# this will be added at the end of <head> | |
within @head do | |
text_node(javascript_include_tag('...)) | |
end | |
end | |
end | |
ActiveAdmin::Views::Pages::Base.send :prepend, AdminPageLayoutOverride |
module AdminPageLayoutOverride
def build_active_admin_head
super
# this will be added at the end of <head>
within head do
text_node(javascript_pack_tag("application"))
end
end
end
ActiveAdmin::Views::Pages::Base.send :prepend, AdminPageLayoutOverride
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 <body>
. Only one <head>
though.
It works correctly if you put the super
at the end instead of the beginning:
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 # Register Stylesheets & Javascripts
section of the active_admin.rb
initializer.
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.)
Note that the above didn't work for me on AA 2.7, but this comment did: activeadmin/activeadmin#5201 (comment)
Note that the above didn't work for me on AA 2.7, but this comment did: activeadmin/activeadmin#5201 (comment)
That worked. Thanks @tobycox.
Thanks. I was finally able to change AA color, even though we're using the same build to deploy to multiple environments
def build_active_admin_head
within super do
text_node("<style>:root {--primary-color: #{Rails.env.production? ? '#ff8b41' : '#505050'};}</style>".html_safe)
end
end
Is there a way to do this now in AA 2.7?
This approach gives me:
... because
@head
isnil
when this is evaluated. Same thing occurs withsuper
at the end of the method too.Actually, answered this myself based upon the source: just replace
@head
withhead
and@body
withbody
, and you're off to the races.