2016-03-04 217 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 
相關問題