【问题标题】:Static files are served up in development but not in production静态文件在开发中提供,但在生产中不提供
【发布时间】:2013-08-20 05:28:00
【问题描述】:

我正在运行 rails 3.2.11。

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

在生产中,我已经将 serve 静态资产设置为 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)

【问题讨论】:

  • 您使用的是哪个网络服务器?这是发生在所有资产上还是仅发生在某些特定资产上?您是否尝试过预编译资产?您必须运行 RAILS_ENV=production bundle exec rake assets:precompile。

标签: ruby-on-rails ruby-on-rails-3.2 asset-pipeline pre-compilation


【解决方案1】:

几件事。

第一。静态资产与资产目录没有任何关系。静态资产是存储在应用程序公共目录中的资产。资产管道编译资产的地方。

第二。查看您的 app/assets/stylesheets/application.css 并查看那里是否需要史诗编辑器,因此它将与其他资产一起预编译。使用require epiceditor/epiceditorrequire_tree epiceditorrequire_tree .。最后一个将编译您文件夹中的所有资产,顺便说一句。

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

【讨论】:

    猜你喜欢
    • 2018-09-25
    • 2019-12-12
    • 2015-10-02
    • 2017-12-30
    • 1970-01-01
    • 2012-06-04
    • 2013-12-22
    • 1970-01-01
    • 2011-08-11
    相关资源
    最近更新 更多