本周开始在新的应用程序上运行最新的rails 3.2.2与资产管道.对于资产,我希望在推送应用程序到heroku时编译资产(而不是在repo中手动编译和存储编译的资产).
The docs suggest this should happen automatically.
我遇到的问题是当我运行git push heroku master时,似乎没有运行rake资源:预编译任务.资产从未编制.这是我得到的输出:
-----> Heroku receiving push -----> Ruby/Rails app detected -----> Installing dependencies using Bundler version 1.1.rc.7 Running: bundle install --without development:test --path vendor/bundle --binstubs bin/ --deployment Using rake (0.9.2.2) ....... ....... Your bundle is complete! It was installed into ./vendor/bundle Cleaning up the bundler cache. -----> Writing config/database.yml to read from DATABASE_URL -----> Rails plugin injection Injecting rails_log_stdout Injecting rails3_serve_static_assets -----> Discovering process types Procfile declares types -> web Default types for Ruby/Rails -> console,rake,worker -----> Compiled slug size is 61.7MB -----> Launching... done,v30 [appname] deployed to Heroku
我的application.rb中启用了资产管道
require File.expand_path('../boot',__FILE__) require "action_controller/railtie" require "action_mailer/railtie" require "active_resource/railtie" require "sprockets/railtie" Bundler.require *Rails.groups(:assets) if defined?(Bundler) module Appname class Application < Rails::Application # ... # Enable the asset pipeline config.assets.enabled = true # Do not boot the app when precompiling assets config.assets.initialize_on_precompile = false end end
任何人知道可能导致问题的原因?如果需要,我很乐意提供更多的代码.如果我运行英雄信息,它表明我正在雪松堆栈上运行.
我不得不打开config.assets.compile = true,以便在生产中停止接收500个错误,尽管这在编译运行时(我不想要)的资产.
解决方法
这似乎已经解决了.我相信这是由于Rakefile不加载资源造成的:预编译任务在生产中.
rakefile正在加载未捆绑到生产中的黄瓜和rspec宝石的任务.因此,资产:预编译任务不可用于生产,所以英雄不试图运行它.
我在环境检查中包装了测试任务,条件如下:
if %(development test).include?(Rails.env) require 'rspec/core' require 'rspec/core/rake_task' end