我最近將一個應用程序從Rails 3.0升級到了3.1。我跟了我能找到使資產管道的任何指示,但是當生產環境總是失敗:Rails資產管道在生產環境中不起作用?
<%= 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 assets:precompile
任務。
我是否缺少明顯的步驟?
編輯:一些額外的細節:
我的資產是app/assets
文件夾中。 app/assets/images
,app/assets/javascripts
,app/assets/stylesheets
等
我看到我的文件生成在我的public/assets
目錄中的名稱和摘要。
app/assets/javascripts/application.js
的確編譯成類似於public/assets/application-6ec417a53cb2bdb949966a153a61e7b1.js
的東西它們最終在public
目錄中。
我使用RSpec,因此有一個類似的設置與test_unit註釋掉。我不知道鏈輪有自己的railtie。非常感謝你做的這些。 –
真棒抓B) – dexter