[英]Assets precompile not being run on heroku cedar for rails 3.2 app
本周開始使用資產管道運行最新的rails 3.2.2。 對於資產,我希望在將應用程序推送到heroku時編譯資產(而不是必須在repo中手動編譯和存儲已編譯的資產)。 文檔表明這應該自動發生 。
我遇到的問題是,當我運行git push heroku master
它似乎沒有運行rake assets:precompile
任務。 資產永遠不會被編譯。 這是我得到的輸出:
-----> 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
有誰知道可能導致問題的原因是什么? 如果需要,我很樂意為您提供更多代碼。 如果我運行heroku info
它表明我正在Cedar堆棧上運行。
我不得不打開config.assets.compile = true
來停止在生產中接收500個錯誤,盡管這會在運行時編譯資產(我不想要)。
這似乎現在已經解決了。 我認為這是由於Rakefile沒有加載資產造成的:生產中的預編譯任務。
rakefile正在加載黃瓜和rspec寶石的任務,這些寶石沒有捆綁到生產中。 因此資產:預編譯任務在生產中不可用,因此heroku不會嘗試運行它。
我將測試任務包裝在環境檢查條件中,如下所示:
if %(development test).include?(Rails.env)
require 'rspec/core'
require 'rspec/core/rake_task'
end
如果您的Rakefile中有任何錯誤,那么將完全跳過預編譯步驟。 對我來說,我指的是僅在我的測試和開發環境中加載的依賴項,而不是生產,因此rakefile是轟炸。
使用@ Lecky-Lao的建議為我工作。
heroku run rake -T --app staging-hawkmo
Running `rake -T` attached to terminal... up, run.1
rake aborted!
cannot load such file -- jasmine-headless-webkit
一旦我看到它就像在環境測試中包裝Rakefile要求一樣簡單。
我通常將它添加到production.rb
:
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
config.assets.precompile += %w( style.css grid.css ... geo.js jquery.flexslider-min.js)
並設置:
config.assets.compile = false
只是在Rails 3.1.3和Rails 3.2.3上都有相同的問題。 按照馬里奧的想法,當我運行“heroku run rake -T”時,rake任務確實存在。 所以任何人都可以從Heroku的反饋中獲得反饋嗎? 我可能只是為此提高票價......
看來這是由於當heroku嘗試啟動/檢查資產時由於致命錯誤而死亡的結果。 這實際上可能與Rails 3.2無關。 我不知道。
我沒有時間等待heroku幫助所以我經歷了下面的痛苦過程來確定問題是什么。 我建議你也這樣做。
創建一個新的,獨立的rails 3.2.2 app。 除了默認文件之外,它沒有任何內容。 創建一個heroku應用程序: heroku create --stack cedar
。 只是為了你的理智,推出這個應用程序,看看預編譯步驟發生在slug編譯期間。
復制到應用程序的每個邏輯塊的新應用程序中。 我從app / assets開始。 (認為它與資產和預編譯有關... nah) cp -R ../ProblemApp/app/assets/* app/assets/
然后添加,提交並將其推送到heroku git remote。
在某些時候,您將復制一組將停止資產的文件:在slug編譯期間出現預編譯消息。 現在,逐個將這些文件還原為原始狀態或注釋掉可疑行並推回到heroku。 再次看到預編譯消息后,您就發現了問題。
事實證明,對我們來說,我有幾個誤報。 當我將配置目錄復制到新應用程序時,應用程序模塊名稱是我們的舊應用程序而不是新應用程序。 這也阻止了預編譯的發生,但這不是我正在尋找的原始原因。
最后,我們有一個rake任務,負責在開發過程中將CSV數據加載到應用程序中。 它有一行引起了問題:
require "#{Rails.root.to_s}/config/environment"
在我們的原始應用程序中注釋掉這一行修復了我們的問題。 這個Rails 3.2是否相關? 為什么heroku運行無關的rake任務? 我不知道。 但是狗屎正在工作。 :)
我有同樣的問題,我按照本指南https://devcenter.heroku.com/articles/rails-asset-pipeline修復它。
問候。
嘗試將以下內容添加到production.rb中
config.assets.precompile = ['*.js', '*.css']
我也找到了這個網站https://coderwall.com/p/ga9l-a
將您的css重命名為.css.erb並在規則中使用asset_path標記。
例如
background: url(<%= asset_path 'bg.png'%>);
如2.3.1中所述http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.