【问题标题】:Assets pipeline with Rails and Heroku使用 Rails 和 Heroku 的资产管道
【发布时间】:2014-03-18 13:17:37
【问题描述】:

我无法解决生产环境的问题。我在 heroku 上的 application.css 是空的,而在开发中它很好。

在我的 application.rb 我添加了这个: config.assets.enabled = true config.assets.compress = false 但还是不行。

预编译也不起作用。在我完成之后,heroku 会发出一条消息,指出它找到了一个清单文件,但仍然 - 无法正常工作。为了回滚它,我使用了 rake assets:clean。消息仍然出现。

我能做什么?我只有一个没有 JS 的 CSS 文件。

应用链接: http://floating-hamlet-8270.herokuapp.com/

我的 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, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, 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 top of the
* compiled file, but it's generally better to create a new file per style scope.
*
*= require_self
*= require_tree .
*/

html, body, h1, h2, h3, h4, h5, h6, p, ul, li {
 margin: 0;
 padding: 0;
}

body {
 font-family: "Noto Sans", sans-serif;
}

【问题讨论】:

    标签: ruby-on-rails heroku asset-pipeline


    【解决方案1】:

    请参考Heroku's documentation以下内容:

    如果在您的应用中检测到 public/assets/manifest.yml,Heroku 将 假设您自己处理资产编译并且不会 尝试编译您的资产。

    您必须删除您的 manifest.yml 文件以让 Heroku 管理您的资产或正确配置它。

    【讨论】:

    • 在这两种情况下,向 Heroku 推送都是正确的,但浏览器无法获取文件。不幸的是,我尝试了文档中的所有内容,但样式仍然没有出现......有没有办法在 Heroku 中禁用链轮?
    【解决方案2】:

    试试下面...

    添加到 gemfile:

    gem 'rails_12factor',组::生产

    添加到/config/production.rb:

    config.serve_static_assets = true

    config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'

    config.assets.compile = true

    见https://medium.com/self-directed-learning/9ba1f595102a

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-15
      • 1970-01-01
      相关资源
      最近更新 更多