我有rails应用程序,它们在本地计算机上运行良好。但是当我在Heroku上部署它时,我在浏览器中出现了下一个错误:
Failed to load resource: the server responded with a status of 404 (Not Found) http://hollow-cloud-nnn.herokuapp.com/stylesheets/application.css
Failed to load resource: the server responded with a status of 404 (Not Found) http://hollow-cloud-nnn.herokuapp.com/javascripts/application.js
我在app \ assets \ javascript和\ app \ assets \ stylesheets文件夹中有这些文件。
这是我的config \ production.rb:
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
# Compress JavaScripts and CSS
config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = true
# Generate digests for assets URLs
config.assets.digest = true
以下是部署的控制台输出:
Using mongoid (2.4.7)
Using rails (3.2.1)
Using sass (3.1.15)
Using sass-rails (3.2.5)
Using uglifier (1.2.3)
Your bundle is complete! It was installed into ./vendor/bundle
Cleaning up the bundler cache.
-----> Writing config/database.yml to read from DATABASE_URL
-----> Rails plugin injection
Injecting rails_log_stdout
Injecting rails3_serve_static_assets
-----> Discovering process types
Procfile declares types -> (none)
Default types for Ruby/Rails -> console, rake, web, worker
-----> Compiled slug size is 15.8MB
-----> Launching... done, v24
http://hollow-cloud-7412.herokuapp.com deployed to Heroku
To git@heroku.com:hollow-cloud-7412.git
cb8ded3..dc103ac master -> master
我该如何解决?
答案 0 :(得分:19)
您应该在生产环境中precompile assets或设置config.assets.compile = true
。
有关heroku开发中心的更多信息,请阅读how to use rails 3.1+ asset pipeline on heroku。
答案 1 :(得分:0)
好像你是一个运行rails 3.1+的mongoid用户。对于Mongoid用户来说,这是一个非常常见的问题,因为文档指示您在config/application.rb
中删除此行
require 'rails/all'
要解决此问题,请将以下行添加到config/application.rb
require 'sprocket/railtie'