Rails 资产管道在生产环境中不起作用?

发布于 2024-12-07 18:10:28 字数 2387 浏览 0 评论 0原文

我最近将一个应用程序从 Rails 3.0 升级到 3.1。我已按照我能找到的用于启用资产管道的任何说明进行操作,但在生产环境中时它总是失败:

<%= javascript_include_tag "application" %>

给我

<script src="/javascripts/application.js" type="text/javascript"></script>

缺少摘要,并且出现以下错误:

cache: [GET /javascripts/application.js] miss
Started GET "/javascripts/application.js" for 127.0.0.1 at 2011-10-03 23:31:36 +0100
ActionController::RoutingError (No route matches [GET] "/javascripts/application.js"):

我尝试了以下变体 中的这些设置

require File.expand_path('../boot', __FILE__)

#require 'rails/all'
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "rails/test_unit/railtie"

if defined?(Bundler)
  # If you precompile assets before deploying to production, use this line
  Bundler.require *Rails.groups(:assets => %w(development test))
  # If you want your assets lazily compiled in production, use this line
  # Bundler.require(:default, :assets, Rails.env)
end


module Blog
  class Application < Rails::Application
    config.autoload_paths += %W(#{config.root}/lib)
    config.encoding = "utf-8"
    config.filter_parameters += [:password]
    config.assets.enabled = true
    config.assets.version = '1.0'
  end
end

application.rb:和完整的 production.rb

Blog::Application.configure do
  config.cache_classes = true
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true
  config.serve_static_assets = false
  config.assets.compress = true
  config.assets.compile = false
  config.assets.digest = true
  config.i18n.fallbacks = true
  config.active_support.deprecation = :notify
end

(减去一些注释)我已经运行了 rake assets:precompile 任务。

我是否遗漏了任何明显的步骤?

编辑:一些其他详细信息:

我的资产位于 app/assets 文件夹中。 app/assets/imagesapp/assets/javascriptsapp/assets/stylesheets 等。

我看到我的文件在我的 中生成>public/assets 目录,包含名称和摘要。

app/assets/javascripts/application.js 确实编译成类似 public/assets/application-6ec417a53cb2bdb949966a153a61e7b1.js 它们最终在 public 目录。

I have recently upgraded an app from Rails 3.0 to 3.1. I have followed any instructions I could find for enabling the asset pipeline but it always fails when in the production environment:

<%= javascript_include_tag "application" %>

gives me

<script src="/javascripts/application.js" type="text/javascript"></script>

which is missing a digest and I get the following error:

cache: [GET /javascripts/application.js] miss
Started GET "/javascripts/application.js" for 127.0.0.1 at 2011-10-03 23:31:36 +0100
ActionController::RoutingError (No route matches [GET] "/javascripts/application.js"):

I've tried variations of these settings in application.rb:

require File.expand_path('../boot', __FILE__)

#require 'rails/all'
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "rails/test_unit/railtie"

if defined?(Bundler)
  # If you precompile assets before deploying to production, use this line
  Bundler.require *Rails.groups(:assets => %w(development test))
  # If you want your assets lazily compiled in production, use this line
  # Bundler.require(:default, :assets, Rails.env)
end


module Blog
  class Application < Rails::Application
    config.autoload_paths += %W(#{config.root}/lib)
    config.encoding = "utf-8"
    config.filter_parameters += [:password]
    config.assets.enabled = true
    config.assets.version = '1.0'
  end
end

and full production.rb (minus some comments)

Blog::Application.configure do
  config.cache_classes = true
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true
  config.serve_static_assets = false
  config.assets.compress = true
  config.assets.compile = false
  config.assets.digest = true
  config.i18n.fallbacks = true
  config.active_support.deprecation = :notify
end

I have ran the rake assets:precompile task.

Am I missing any obvious steps?

Edit: Some additional details:

My assets are in app/assets folder. app/assets/images, app/assets/javascripts, app/assets/stylesheets, etc.

I see my files generated in my public/assets directory with names and digests.

app/assets/javascripts/application.js does indeed compile to something like public/assets/application-6ec417a53cb2bdb949966a153a61e7b1.js They end up in the public directory.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

冷情妓 2024-12-14 18:10:28

链轮未加载。

为了删除以前版本的rails中的活动记录(这个问题在 Rails 3(测试版)中删除 ActiveRecord),require 'rails/all' 被替换为

require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "rails/test_unit/railtie"

这里缺少的是链轮/铁轨

Sprockets is not getting loaded.

In an effort to remove active record in a previous version of rails (a la this question Remove ActiveRecord in Rails 3 (beta)) the require 'rails/all' was replaced by

require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "rails/test_unit/railtie"

What was missing here was sprockets/railtie

沦落红尘 2024-12-14 18:10:28

请参阅升级到 Rails 3.1 Railscast

确保您的资源位于app/assets 文件夹。 app/assets/imagesapp/assets/javascriptsapp/assets/stylesheets等。

执行rake assets:precompile< /code>

您应该会看到在 app/public/assets 目录中生成的文件,其中包含名称和摘要(如果启用)。

app/assets/javascripts/application.js 将编译为 /assets/application-6ec417a53cb2bdb949966a153a61e7b1.js

如果资产的命名类似于上面的摘要,Production .rb 应具有以下配置:

# Generate digests for assets URLs
config.assets.digest = true

如果您查看网页源代码,您应该会看到类似于以下内容的内容:

<script src="/assets/application-6ec417a53cb2bdb949966a153a61e7b1.js" type="text/javascript"></script>

尝试手动加载文件通过访问 http://example.com//assets/application-6ec417a53cb2bdb949966a153a61e7b1.js

文件应该加载,如果没有尝试检查权限和进一步的日志。

See the Upgrading to Rails 3.1 Railscast

Make sure your assets are in app/assets folder. app/assets/images, app/assets/javascripts, app/assets/stylesheets, etc.

Execute rake assets:precompile

You should see files generated in your app/public/assets directory with names and digests if enabled.

app/assets/javascripts/application.js would compile to /assets/application-6ec417a53cb2bdb949966a153a61e7b1.js

If the asset is named similar to above with a digest, Production.rb should have the following config:

# Generate digests for assets URLs
config.assets.digest = true

If you look at the web page source you should see something similar to the following:

<script src="/assets/application-6ec417a53cb2bdb949966a153a61e7b1.js" type="text/javascript"></script>

Try to manually load the file by going to http://example.com//assets/application-6ec417a53cb2bdb949966a153a61e7b1.js

The file should load, if not try checking permissions and further logs.

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