Ruby on rails rails:application.css加载资源失败:服务器响应状态为404(未找到)
我给heroku推了一些代码,我的应用程序坏了。 我在浏览器控制台中遇到以下错误: 未能加载资源:服务器以404状态响应 (未找到)2 未能加载资源:服务器以404状态响应 (未找到) 这是今天第二次发生。首先,我将新代码推送到服务器上,它就开始工作了。但现在我开始担心是否出了什么问题。 在本地,它运行良好Ruby on rails rails:application.css加载资源失败:服务器响应状态为404(未找到),ruby-on-rails,heroku,Ruby On Rails,Heroku,我给heroku推了一些代码,我的应用程序坏了。 我在浏览器控制台中遇到以下错误: 未能加载资源:服务器以404状态响应 (未找到)2 未能加载资源:服务器以404状态响应 (未找到) 这是今天第二次发生。首先,我将新代码推送到服务器上,它就开始工作了。但现在我开始担心是否出了什么问题。 在本地,它运行良好 My application.js file // This is a manifest file that'll be compiled into application.js, wh
My application.js file
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery.turbolinks
//= require jquery_ujs
//= require bootstrap
//= require_tree .
//= require turbolinks
My application.css文件
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any styles
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
* file per style scope.
*
*= require bootstrap
*= require_tree .
*= require_self
*= require_custom
*/
更改
config.assets.compile=true
在config/environments/production.rb中,确保使用rails帮助程序获取资产路径:不要在代码中硬编码“/assets/name.extension”路径,Heroku将为您编译资产,它们的最终路径更像:/assets/application-6aae32862efc758cf08c7b7fc0e85e15.js 简单地使用
和
助手方法应该适合您
如果您仍有问题,请按照Heroku帮助中的调试部分进行操作:
特别是:
$ heroku run rails console
> puts helper.asset_path("application.js")
/assets/application-6aae32862efc758cf08c7b7fc0e85e15.js
你能告诉我们你是如何在你的html中包含这些内容的吗<代码>?Heroku不需要这些,请参阅此处的官方文档: