css - Rails 样式表未在 heroku 上加载(生产模式)

标签 css ruby-on-rails heroku

我的样式表停止在 heroku 上加载(仅限生产模式,在本地一切正常)。

这是 heroku 日志中的错误信息

ActionController::RoutingError (No route matches [GET] "/assets/application-cdff05ced6e18e533fc2f71d065b63f48ce16d3045406917ed854476a7eb1702.css")

确实是当我运行的时候

heroku rake assets:precompile

其他文件被预编译

/app/vendor/bundle/ruby/2.2.0/gems/rb-readline-0.5.3/lib/readline.rb:458: warning: already initialized constant Readline::HISTORY
/app/vendor/bundle/ruby/2.2.0/gems/rb-readline-0.5.3/lib/readline.rb:486: warning: already initialized constant Readline::FILENAME_COMPLETION_PROC
/app/vendor/bundle/ruby/2.2.0/gems/rb-readline-0.5.3/lib/readline.rb:517: warning: already initialized constant Readline::USERNAME_COMPLETION_PROC
/app/vendor/bundle/ruby/2.2.0/gems/rb-readline-0.5.3/lib/readline.rb:523: warning: already initialized constant Readline::VERSION
I, [2017-04-17T09:41:44.957818 #4]  INFO -- : Writing /app/public/assets/application-f295a8fe23711032f76515a85070c9a4a7195e35bb2ea56572a87cab10734aef.js
I, [2017-04-17T09:41:44.958361 #4]  INFO -- : Writing /app/public/assets/application-f295a8fe23711032f76515a85070c9a4a7195e35bb2ea56572a87cab10734aef.js.gz
I, [2017-04-17T09:41:50.103993 #4]  INFO -- : Writing /app/public/assets/application-e86e4356a42c5e1f39646b26c890239ee4734ecd3a9a5e4214aea2a68d0e4509.css
I, [2017-04-17T09:41:50.104211 #4]  INFO -- : Writing /app/public/assets/application-e86e4356a42c5e1f39646b26c890239ee4734ecd3a9a5e4214aea2a68d0e4509.css.gz

有很多关于这个主题的帖子,现在这是我的 production.rb 文件中的内容,经过几次其他尝试都不成功。

config.serve_static_files = true
config.assets.initialize_on_precompile = false
config.assets.compile = true

如果你有任何想法,请告诉我。谢谢。

最佳答案

在本地机器上运行以下命令:

RAILS_ENV=production rake assets:precompile

然后将所有生成的 list 文件推送到 heroku。

关于css - Rails 样式表未在 heroku 上加载(生产模式),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43449123/

相关文章:

ruby-on-rails - 防止为每个评论调用 upvote 模型

ruby-on-rails - ActiveRecord 销毁方法 - 参数数量错误(0 代表 1)

node.js - heroku nodejs app 如何获取应用程序根目录的绝对路径?

ruby-on-rails - 如何使用 Heroku 阻止推荐垃圾邮件

html - 在标题中的图像上构建文本

html - 如何在 CSS 中应用字体抗锯齿效果?

javascript - 无法删除 chrome 中的样式属性

html - Bootstrap ul导航向右浮动但从左到右排序

ruby-on-rails - RSpec 设置 session 对象

reactjs - 运行 ReactJS/TailwindCSS/Heroku 时出错 : React Refresh runtime should not be included in the production bundle