我的样式表停止在 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/