12

I want to add Gon ( https://github.com/gazay/gon ) to my activeadmin

but I need to add the line

<%= include_gon %>

to the head section in the layout

but I can't figure out how?

5 Answers 5

27

To add to Mexxer's comment. Go to `config/initializers/active_admin.rb

At the bottom of the page, you'll find the following:

# == Register Stylesheets & Javascripts
#
# We recommend using the built in Active Admin layout and loading
# up your own stylesheets / javascripts to customize the look
# and feel.
#
# To load a stylesheet:
#   config.register_stylesheet 'my_stylesheet.css'
#
# To load a javascript file:
#   config.register_javascript 'my_javascript.js'

Uncomment the last line and replace my_javascript.js with your file, like this...

# To load a javascript file:
config.register_javascript 'invoices.js'

That file can be located at app/assets/javascripts/invoices.js

Sign up to request clarification or add additional context in comments.

1 Comment

register_javascript option has been deprecated in favor of requiring the JS file in active_admin.js
6

This may also be relevant:

# The Active Admin equivalent of putting this in your application layout:
# <head>
#   <%= cloudinary_js_config %>
# </head>

module ActiveAdmin
  module Views
    module Pages
      class Base < Arbre::HTML::Document

        alias_method :original_build_head, :build_active_admin_head

        def build_active_admin_head
          original_build_head

          within @head do
            text_node include_gon
          end
        end

      end
    end
  end
end

Source: https://gist.github.com/seanlinsley/9786622

Comments

5

The register_javascript config will be deprecated in V2.

So instead of change config/initializers/active_admin.rb, you can change assets/javascripts/active_admin.js, just put the name file of your .js like

//= require active_admin/base
//= require activeadmin_addons/all
//= require masks

this file is located inside of assets folder, as masks.js

Comments

0
Rails.application.config.after_initialize do
  javascripts = [] 
  javascripts << "//maps.googleapis.com/maps/api/js?sensor=false&key="
  javascripts += ActiveAdmin.application.javascripts.to_a
  ActiveAdmin.application.javascripts.replace javascripts
end

https://github.com/activeadmin/activeadmin/issues/340#issuecomment-92512556

Comments

0

Nowadays there is

active_admin_namespace.head

Very convenient. Do not forget to html_safe concatenated string.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.