12

我想将 Gon ( https://github.com/gazay/gon ) 添加到我的 activeadmin

但我需要添加该行

<%= include_gon %>

到布局中的头部

但我不知道怎么做?

4

5 回答 5

28

添加到 Mexxer 的评论中。转到`config/initializers/active_admin.rb

在页面底部,您会发现以下内容:

# == 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'

取消注释最后一行并将 my_javascript.js 替换为您的文件,如下所示...

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

该文件可以位于app/assets/javascripts/invoices.js

于 2012-07-02T16:24:58.990 回答
6

这也可能是相关的:

# 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

来源:https ://gist.github.com/seanlinsley/9786622

于 2014-09-24T10:26:16.953 回答
4

register_javascript 配置将在 V2 中弃用。

因此config/initializers/active_admin.rb,您可以更改 `assets/javascripts/active_admin.js,而不是更改,只需将 .js 的名称文件放在

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

此文件位于 assets 文件夹内,如 mask.js

于 2018-12-13T12:47:48.287 回答
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

于 2015-10-17T14:48:35.970 回答
0

如今有

active_admin_namespace.head

很方便。不要忘记html_safe连接字符串。

于 2020-12-01T22:07:58.113 回答