静态文件在开发中提供但不在生产中提供

问题描述 投票:0回答:1

我正在运行rails 3.2.11。

我正在使用一个JS插件(epiceditor),它要求我有几个js调用的静态文件。 在开发中,我能够轻松地通过资产管道访问文件。

在生产中,我已经将服务静态资产设置为true,但它仍然没有出现。

 config.serve_static_assets = true

这些文件保存在assets目录中:

- assets
    - stylesheets
       - epiceditor

在开发中,它有效: 在此输入图像描述

在生产中,它不起作用: 在此输入图像描述

正在执行JS代码以插入css:

  function _insertCSSLink(path, context, id) {
    id = id || '';
    var headID = context.getElementsByTagName("head")[0]
      , cssNode = context.createElement('link');

    _applyAttrs(cssNode, {
      type: 'text/css'
    , id: id
    , rel: 'stylesheet'
    , href: path
    , name: path
    , media: 'screen'
    });

    headID.appendChild(cssNode);
  }

我在控制台中看到的内容:

Resource interpreted as Stylesheet but transferred with MIME type application/json: "http://www.fulfilled.in/assets/epiceditor/epiceditor.css". application.js:30
(anonymous function)
ruby-on-rails ruby-on-rails-3.2 asset-pipeline pre-compilation
1个回答
2
投票

几件事。

1。 静态资产与assets目录无关。 静态资产是存储在应用程序的公共目录中的资产。 资产管道在哪里编译资产。

第2位。 查看你的app / assets / stylesheets / application.css,看看是否需要epiceditor,所以它将与其他资产一起预编译。 使用它require epiceditor/epiceditorrequire_tree epiceditorrequire_tree . 。 最后一个将编译你的文件夹中的所有资产,顺便说一句。

3。 你在生产中使用http服务器(Apache或Nginx)吗? 如果是这样,您应该关闭static_assets服务,因为它将由服务器处理,并查看您的服务器配置。

© www.soinside.com 2019 - 2024. All rights reserved.