推到Heroku后找不到CSS [英] Can't find CSS after pushing to Heroku
问题描述
当我在本地运行时,一切正常,但当我推送到heroku时失败。我发现我需要修改 app / assets / stylesheets /
中的所有.css文件以使 .css.scss
扩展,并确保我的Gemfile包含:
gem'sass-rails','4.0.1'
组:生产,:分期做
gem'rails_12factor'#for heroku
结束
在我的 .css.scss
文件中,我现在使用 image-url()
来代替 url()
指向指纹图像(由heroku和资产编译业务进行指纹识别和重组)。
in app / views / layouts / mycontrollername.html.erb
:
< head>
...
<%= stylesheet_link_tagpath / to / css / file%>
< / head>
但我仍然找不到正确的路径。当我看到源代码时,除了指纹之外,我看到了我期望的路径: path / to / css / file.css
而不是路径/到/ CSS /文件somemd5hash.css
。请注意,该路径不包含assets / path / to / css / file。
http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets
编辑
我已确认在public / assets /中的heroku上没有编译过的css文件。有一个application.js文件(它是空的),即使我为每个控制器都有一个.js.coffee文件。我没有application.css,每个控制器只有一个.css。
这个gem帮我克服了它,猜猜会很快融入到rails master中:
$ b $ gem'sprockets_better_errors'
https://github.com/schneems/sprockets_better_errors
Everything works fine when I run locally, but fails when I push to heroku. I've discovered that I need to modify all of the .css files in app/assets/stylesheets/
to have .css.scss
extensions and ensure my Gemfile contains:
gem 'sass-rails', '4.0.1'
group :production, :staging do
gem 'rails_12factor' # for heroku
end
Within my .css.scss
files, I now use image-url()
instead of url()
to point to the fingerprinted image (fingerprinted and reorganized by heroku and asset compilation business).
in app/views/layouts/mycontrollername.html.erb
:
<head>
...
<%= stylesheet_link_tag "path/to/css/file" %>
</head>
But I still can't find the right path. When I look at the source, I see the path I expect except for the fingerprint: path/to/css/file.css
instead of path/to/css/file-somemd5hash.css
. Note that the path does NOT include assets/path/to/css/file.
http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets
EDIT
I've confirmed that there are no compiled css files on heroku in public/assets/. There is one application.js file (it's empty) even though I have a .js.coffee file for each controller. I have NO application.css, only a .css for each controller.
This gem helped me get over it, which I guess will be merged into rails master soon:
gem 'sprockets_better_errors'
https://github.com/schneems/sprockets_better_errors
这篇关于推到Heroku后找不到CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!