【问题标题】:Can't find CSS after pushing to Heroku推送到 Heroku 后找不到 CSS
【发布时间】:2014-01-25 21:37:48
【问题描述】:

当我在本地运行时一切正常,但当我推送到 heroku 时却失败了。我发现我需要修改 app/assets/stylesheets/ 中的所有 .css 文件以具有 .css.scss 扩展名并确保我的 Gemfile 包含:

gem 'sass-rails', '4.0.1'
group :production, :staging do
  gem 'rails_12factor' # for heroku
end

在我的.css.scss 文件中,我现在使用image-url() 而不是url() 来指向指纹图像(由heroku 和资产编译业务进行指纹和重组)。

app/views/layouts/mycontrollername.html.erb:

<head>
  ...
  <%= stylesheet_link_tag "path/to/css/file" %>
</head>

但我仍然找不到正确的路径。当我查看源代码时,我看到了我期望的路径,除了指纹:path/to/css/file.css 而不是path/to/css/file-somemd5hash.css。请注意,路径不包括 assets/path/to/css/file。

http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets

编辑

我已经确认在 public/assets/ 中的 heroku 上没有编译过的 css 文件。即使我为每个控制器都有一个 .js.coffee 文件,也有一个 application.js 文件(它是空的)。我没有 application.css,每个控制器只有一个 .css。

【问题讨论】:

  • 我没有一个很好的答案,但是这个解决方法对我有用:在config/environments/production.rb 中注释掉config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? 并用config.serve_static_files = true 替换它我希望我知道为什么这有效.. .

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


【解决方案1】:

这个 gem 帮助我克服了它,我猜它很快就会被合并到 rails master:

gem 'sprockets_better_errors'

https://github.com/schneems/sprockets_better_errors

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-09
    • 2019-02-13
    • 1970-01-01
    • 2014-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多