Rails 3.1 资产在生产中没有指纹
刚开始适应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>
在页面的源代码中,没有生成哈希码,并且两个资产都有路由错误:
Routing Error
No route matches [GET] "/stylesheets/application.css"
这是什么原因?我是不是忘记做某事了?
环境/生产.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
非常感谢。
添加更多信息:
在layouts/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"
取消评论然后一切都很好。
将此留给其他人来提醒我的菜鸟错误。
非常感谢理查德。您的答案不是最终答案,但它很有帮助,确实值得投赞成票。
Just started to adapted to rails 3.1, I started to write coffeescript and sass and everything works fine in development. When I run the server in production, I only get:
<link href="/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />
<script src="/javascripts/application.js" type="text/javascript"></script>
in the source code of the page, there's no hashcode generated and both assets has routing errors:
Routing Error
No route matches [GET] "/stylesheets/application.css"
What's the cause of this? Did I forget to do something?
settings in environments/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
Thank you very much.
Add more information:
in layouts/application.html.erb, I am using the following to include the assets:
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
And I've tried bundle exec rake assets:precompile
which runs without output anything and then run rails s -e production
, the problem persists.
And I also tried to set config.assets.compile = true
and then run rails s -e production
, the problem still persists.
Please help.
More information.
I've seen that the compiled js and css are generated in public/assets folder, but in production enviroment, the files are included without the hash code.
Help.
Solution:
Just checked again my project, and found that the root cause is when I was editing application.rb for the support of mongodb. I accidentally commented
require "sprockets/railtie"
uncomment it then everything is fine.
Leave this for others to remind my rookie mistake.
Thank you very much Richard. Your answer is not final anwser but it helps a lot, really deserves an up vote.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查是否已在 application.rb 中打开管道:
config.assets.enabled = true
您是否使用正确的辅助方法来编写标签?辅助方法的路径中不应包含 /styleheets 和 /javascript。像这样(在 erb 内):
您还需要运行预编译任务作为部署过程的一部分来创建文件,因为您已将编译设置为 false。
资产管道指南展示了如何使用 capistrano 进行设置。
Check that you have the pipeline turned on in application.rb:
config.assets.enabled = true
Are you using the correct helper methods for writing the tags? The helper methods should not have the /styleheets and /javascript in the path. Like this (inside erb):
You will also need to run the precompile task as part of the deploy processs to create the files, since you've set compile to false.
The asset pipeline guide shows how to set this up with capistrano.