11

在我的本地机器上,当我查看我的 Rails 应用程序时,我的样式表已成功链接,/assets/stylesheets/但在 Heroku 上,它可能更改为/stylesheets/目录public中并且不起作用!public/stylesheets如何让我的样式表在编译时移到?

编辑:

之后的文件目录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

这是我的样式表链接application.html.haml

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

gem flatui-rails在我的 Gemfile*= require flat-ui中,在我的application.css文件中。

编辑2:

清除我的public/assets文件夹,添加public/assets/*到我的.gitignore并推送到我的 Heroku 存储库。在 slug 编译期间,Heroku 运行了资产管道并制作了/assets/application-b2c82b0573602f3a368a26f36b99542b.css它也链接到我网站的源代码中,但是样式没有加载,The page you were looking for doesn't exist.当我尝试导航到样式表时我得到了......现在怎么办?

这是我的application.html.haml

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

2 回答 2

19

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

于 2013-04-18T04:13:40.583 回答
0

与其将已编译的资产签入 Git,不如先阅读以下内容:https ://devcenter.heroku.com/articles/ruby-support#plugin-injection-in-rails-4

您可以添加此宝石

宝石'rails_12factor'

或专门添加此宝石

rails_serve_static_assets

或手动更改配置config/environments/production.rb

config.serve_static_assets = true

于 2013-09-30T04:45:57.460 回答