2016-03-04 317 views
0

我将一些代码推送到了heroku,并且我的应用程序崩溃了。 我得到这个错误,在浏览器控制台:rails:application.css加载资源失败:服务器响应状态为404(未找到)

https://agile-mesa-47878.herokuapp.com/javascripts/application.js无法加载资源:服务器与无法加载资源的404 (未找到)2 https://agile-mesa-47878.herokuapp.com/stylesheets/application.css 状态回应:该服务器的状态回应404 (未找到)

enter image description here

enter image description here

今天发生了第二次。首先,我只是将新代码推送到服务器,并开始工作。但现在我开始担心是否有什么问题。 当地正常工作

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 

我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 
*/ 
+0

你能告诉我们你是如何有这个在您的HTML? '<%= javascript_include_tag'应用程序'%>'? – Leito

回答

0

变化config.assets.compile = true 在配置/环境/ production.rb

+0

Heroku不需要这个功能,请参阅官方文档:https://devcenter.heroku.com/articles/rails-4-asset-pipeline – Leito

0

确保您使用Rails的helper,让您的资产路径:不要在你的代码中硬编码'/assets/name.extension'路径,Heroku会为你编译资产,他们的最终路径看起来更像这样:/assets/application-6aae32862efc 758cf08c7b7fc0e85e15.js

只需使用<%= javascript_include_tag 'application' %><%= stylesheet_link_tag 'application' %>辅助方法应该适合您。

如果您仍然有麻烦,你怎么样遵循的Heroku的帮助调试节:https://devcenter.heroku.com/articles/rails-4-asset-pipeline#debugging

特别是:

$ heroku run rails console 
> puts helper.asset_path("application.js") 
/assets/application-6aae32862efc758cf08c7b7fc0e85e15.js 
相关问题