资源加载失败:服务器响应状态为404(未找到)

11

我有一个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

我该如何修复它?
2个回答

22

我试图修复它,但是没有成功。我已经更新了我的问题以提供更多信息。 - ceth
Rails是否在“...herokuapp.com/stylesheets/application.css”文件夹中搜索文件?(缺少“public”文件夹。) - ceth
你尝试重新启动应用程序了吗?在实时编译期间,它将在“/public/assets”文件夹中生成文件。 - NARKOZ

0

看起来你是一个运行 Rails 3.1+ 的 Mongoid 用户。对于 Mongoid 用户来说,这是一个相当常见的问题,因为文档指导你删除 config/application.rb 中的这一行。

require 'rails/all'

为了解决这个问题,请在config/application.rb中添加以下行。
require 'sprocket/railtie'

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接