Rails 3.1资产在生产中没有指纹 [英] Rails 3.1 assets has no fingerprint in production

查看:32
本文介绍了Rails 3.1资产在生产中没有指纹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚开始适应Rails 3.1,我开始编写coffeescript和sass,一切在开发中都可以正常工作.在生产环境中运行服务器时,只会得到:

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?

environment/production.rb中的设置:

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

非常感谢您.

添加更多信息:

在layouts/application.html.erb中,我使用以下内容包括资产:

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 %>

我尝试了bundle exec rake assets:precompile,该命令在不输出任何内容的情况下运行,然后运行rails s -e production,问题仍然存在.

And I've tried bundle exec rake assets:precompile which runs without output anything and then run rails s -e production , the problem persists.

我还尝试设置config.assets.compile = true,然后运行rails s -e production,问题仍然存在.

And I also tried to set config.assets.compile = true and then run rails s -e production , the problem still persists.

请帮助.

更多信息. 我已经看到,已编译的js和css是在public/assets文件夹中生成的,但是在生产环境中,文件中没有哈希码.

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.

帮助.

解决方案: 只是再次检查了我的项目,发现根本原因是当我在编辑application.rb以获得mongodb的支持时.我不小心评论了

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.

非常感谢Richard.您的答案不是最终答案,但可以帮上很多忙,真的值得您投票.

Thank you very much Richard. Your answer is not final anwser but it helps a lot, really deserves an up vote.

推荐答案

检查是否已在application.rb中打开管道:

Check that you have the pipeline turned on in application.rb:

config.assets.enabled = true

config.assets.enabled = true

您是否使用正确的帮助程序方法来编写标签?辅助方法的路径中不应包含/styleheets和/javascript.像这样(在erb内部):

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):


javascript_include_tag "application"
stylesheet_link_tag "application"

由于已将compile设置为false,因此在部署过程中,您还需要运行预编译任务以创建文件.

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.

资产管道指南显示了如何使用capistrano进行设置.

The asset pipeline guide shows how to set this up with capistrano.

这篇关于Rails 3.1资产在生产中没有指纹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆