我将一些代码推送到heroku并且我的应用程序崩溃了。 我在浏览器控制台中遇到了这个错误:
https://agile-mesa-47878.herokuapp.com/javascripts/application.js无法加载资源:服务器响应状态为404 (未找到)2 https://agile-mesa-47878.herokuapp.com/stylesheets/application.css 无法加载资源:服务器响应状态为404 (未找到)
这发生在今天的第二次。首先,我只是将新代码推送到服务器并开始工作。但现在我开始担心如果出了什么问题。 在本地它可以正常工作
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 :(得分:0)
更改config.assets.compile = true
在config / environments / production.rb
答案 1 :(得分:0)
确保使用rails帮助程序来获取资产路径:永远不要硬代码' /assets/name.extension'在你的代码中,Heroku将为你编译资产,它们的最终路径看起来更像: /assets/application-6aae32862efc758cf08c7b7fc0e85e15.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