Can't find CSS after pushing to Heroku

2019-08-04 08:14发布

问题:

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.

回答1:

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