我有我的production.rb環境文件下面的配置線,按照指示在this article:在Heroku
config.cache_store = :mem_cache_store, ENV["MEMCACHEDCLOUD_SERVERS"].split(','), { :username => ENV["MEMCACHEDCLOUD_USERNAME"], :password => ENV["MEMCACHEDCLOUD_PASSWORD"] }
但是,當我嘗試部署,我會得到一個錯誤:
Running: rake assets:precompile rake aborted!
undefined methodsplit' for nil:NilClass
block in '
/tmp/build_abdc.../config/environments/production.rb:107:in
這是因爲配置變量在編譯期間不可用。有一個Heroku實驗室add-on,你可以用它來解決這個問題,但它帶有Heroku的警告:「使用這個實驗室功能被認爲與Heroku最佳實踐相反。」
那麼什麼是當談到在生產配置中使用ENV變量的最佳做法?他們是否應該全部包裝在救援處理程序中,以便Heroku在編譯期間忽略它們?
也許你可以嘗試設置移動到一個初始化:HTTP://計算器.com/questions/5810289/setting-the-cache-store-in-an-initializer – steakchaser
@steakchaser - 謝謝但是這並沒有改變任何東西 - 該行仍然在編譯時遇到併產生相同的錯誤 – Yarin
muha!我喜歡資產管道!你嘗試設置'initialize_on_precompile'嗎?我不知道這是否仍然是一個在rails4中的東西,但它在heroku上多次保存我的屁股http://stackoverflow.com/questions/11889131/precompile-failing-on-heroku-with-initialize-on-precompile-set - 假的 – phoet