Rails Stylesheets on Heroku

守給你的承諾、 提交于 2019-12-21 07:36:20

问题


On my local machine, when I view my Rails App, my stylesheets are successfully linked at /assets/stylesheets/ but on Heroku, it is changed to /stylesheets/ presumably in the public directory and does not work! How do I get my stylesheets to move to public/stylesheets on compilation?

EDIT:

File directory after rake assets:precompile

app
  assets
    stylesheets
      application.css
      application.min.css
      home.css
      home.css.scss
      home.min.css
      scaffolds.css
      scaffolds.css.scss
      scaffolds.min.css
      startups.css
      startups.css.scss
public
  assets
    application-3701cb84bbc3c20d5a7ec1aac608fbdb.js
    application-3701cb84bbc3c20d5a7ec1aac608fbdb.js.gz
    application-f7ff7ad51f3528ccca1b5c7f2d5b5915.css
    application-f7ff7ad51f3528ccca1b5c7f2d5b5915.css.gz
    manifest-ad3babc6c84cc0b38f1a98eb594b8235.json
    rails-afd7b40a0142ed24738b640e78388de4.png

Here is my stylesheet link in application.html.haml:

stylesheet_link_tag "flat-ui", "home.min", media: "all"

gem flatui-rails is in my Gemfile and *= require flat-ui is in my application.css file.

EDIT 2:

Cleared my public/assets folder, added public/assets/* to my .gitignore and pushed to my Heroku repo. During slug compilation Heroku ran the asset pipline and made /assets/application-b2c82b0573602f3a368a26f36b99542b.css which is also linked in the source code of my site, but the styles don't load and I get The page you were looking for doesn't exist. when I try to navigate to the style sheet... Now what?

Here's my application.html.haml:

!!! 5
%html
  %head
    %title StartupCrawler
    = stylesheet_link_tag "application", media: "all"
    = csrf_meta_tags
  = yield

回答1:


Michael, I before you push to heroku try:

rake assets:precompile

This will precompile them in the public folder so that they can be served to Heroku. Let me know if that didn't work.

Also, make sure the following line exists in config/environments/production.rb

config.serve_static_assets = true

Then of course

git push heroku master




回答2:


Instead of checking in compiled assets into Git, first read this: https://devcenter.heroku.com/articles/ruby-support#plugin-injection-in-rails-4

You can either add this gem

gem 'rails_12factor'

or add this gem specifically

rails_serve_static_assets

or manually change the config in config/environments/production.rb

config.serve_static_assets = true



来源:https://stackoverflow.com/questions/16074170/rails-stylesheets-on-heroku

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!