【问题标题】:Activeadmin assets loading in every non admin page在每个非管理页面中加载 Activeadmin 资产
【发布时间】:2019-06-14 21:58:59
【问题描述】:

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

提前感谢您的帮助

  • application.html.erb
<!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>
  • application.css
/*
 * 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文件

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-5 activeadmin


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-09
      • 2015-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-18
      • 1970-01-01
      相关资源
      最近更新 更多