lar*_*hao 9 ruby-on-rails-3.1 asset-pipeline
刚刚开始适应rails 3.1,我开始编写coffeescript和sass,一切都在开发中运行良好.当我在生产中运行服务器时,我只得到:
<link href="/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />
<script src="/javascripts/application.js" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)
在页面的源代码中,没有生成哈希码,并且两个资产都有路由错误:
Routing Error
No route matches [GET] "/stylesheets/application.css"
Run Code Online (Sandbox Code Playgroud)
这是什么原因?我忘记做某事吗?
环境/ 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
Run Code Online (Sandbox Code Playgroud)
非常感谢你.
添加更多信息:
在layouts/application.html.erb中,我使用以下内容来包含资产:
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
Run Code Online (Sandbox Code Playgroud)
而且我已经尝试了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"
Run Code Online (Sandbox Code Playgroud)
取消注释然后一切都很好.
留给别人提醒我的菜鸟错误.
非常感谢理查德.你的答案不是最后的答案,但它有很大的帮助,真的值得投票.
| 归档时间: |
|
| 查看次数: |
3674 次 |
| 最近记录: |