在每个非管理页面中加载 Activeadmin 资产

Activeadmin assets loading in every non admin page

我 运行 遇到设置 activeadmin gem 的问题。 运行 很好,但问题是它正在我的主布局视图中加载 activeadmin 所需的资产。我想知道如何让它仅在访问 admin 路径时将 CSS 和 JS 文件导入视图。

预先感谢您的帮助

<!DOCTYPE html>
<html>
  <head>
    <title>Example</title>
    <%= csrf_meta_tags %>
    <%= csp_meta_tag %>

    <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %>
    <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
  </head>

  <body>
    <%= render "shared/main_nav" %>
    <%= yield %>
  </body>
</html>
/*
 * This is a manifest file that'll be compiled into application.css, which will include all the files
 * listed below.
 *
 * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's
 * vendor/assets/stylesheets directory can be referenced here using a relative path.
 *
 * You're free to add application-wide styles to this file and they'll appear at the bottom of the
 * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
 * files in this directory. Styles in this file should be added after the last require_* statement.
 * It is generally better to create a new file per style scope.
 *
 *= require_tree .
 *= require_self
 */

application.css

的同一路径下还有一个 active_admin.scss 文件

CSS 清单中的 require_tree 指令需要当前目录中的所有样式表。

因此您可以删除 require_tree 并仅包含您想要的文件。