刚开始适应rails 3.1时,我开始编写coffeescript和sass,并且所有工作都很好地开发。当我运行在生产服务器上,我只得到:Rails 3.1资产在生产中没有指纹
<link href="/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />
<script src="/javascripts/application.js" type="text/javascript"></script>
在页面的源代码
,没有生成散列码和两个资产具有路由错误:
Routing Error
No route matches [GET] "/stylesheets/application.css"
什么是这个原因?我忘了做什么?
设置在环境/ production.rb:
# Settings specified here will take precedence over those in config/application.rb
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# 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 = false
# Generate digests for assets URLs
config.assets.digest = true
config.active_support.deprecation = :notify
非常感谢你。
添加更多信息:
在布局/ application.html.erb,我使用下面包括资产:
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
我已经试过bundle exec rake assets:precompile
它运行无输出任何东西,然后运行rails s -e production
,问题依然存在。
而且我也尝试设置config.assets.compile = true
然后运行rails s -e production
,问题仍然存在。
请帮忙。
更多信息。 我已经看到编译后的js和css是在public/assets文件夹中生成的,但在生产环境中,这些文件没有哈希代码。
帮助。
解决方案: 只是检查了一遍我的项目,发现根本原因是当我编辑application.rb中的支持的MongoDB。我不小心评论了
require "sprockets/railtie"
取消注释它然后一切都很好。
给他人留下这个提醒我的菜鸟的错误。
非常感谢Richard。你的答案不是最终的答案,但是它有很大的帮助,确实值得投票。
感谢理查德,我在主帖中添加了附加信息。我必须使用capistrano来获得此功能吗?我只是试图在我的本地运行“rails s -e production”。 – larryzhao
如果你是本地的,那么你必须在本地运行它。如果这是部署到生产生产环境的方式,则只需要Capistrano任务。升级你的应用程序到3.1.1.rc2并重新运行任务。我认为在预编译任务中有一些修复可以解决这个问题。 –