我最近将应用程序从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"):
我在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
和完整的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资产:预编译任务.
我错过了任何明显的步骤吗?
编辑:一些其他细节:
我的资产位于app / assets文件夹中. app / assets / images,app / assets / javascripts,app / assets / stylesheets等.
app / assets / javascripts / application.js的确编译成public / assets / application-6ec417a53cb2bdb949966a153a61e7b1.js.它们最终会出现在公共目录中.
解决方法
链轮没有加载.
为了删除先前版本的rails中的活动记录(问题Remove ActiveRecord in Rails 3 (beta)),需要’rails / all’被替换为
require "action_controller/railtie" require "action_mailer/railtie" require "active_resource/railtie" require "rails/test_unit/railtie"
这里缺少的是链轮/铁路