Rails 3.1 资产在生产中没有指纹

发布于 2024-12-08 14:55:38 字数 2046 浏览 0 评论 0原文

刚开始适应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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我三岁 2024-12-15 14:55:38

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


config.assets.enabled = true

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

javascript_include_tag "application"
stylesheet_link_tag "application"

您还需要运行预编译任务作为部署过程的一部分来创建文件,因为您已将编译设置为 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):

javascript_include_tag "application"
stylesheet_link_tag "application"

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文