LoginSignup
3
2

More than 5 years have passed since last update.

Herokuデプロイで失敗したときの対処

Last updated at Posted at 2018-01-04

Railsチュートリアル13章を取り組んでいた時に、最後の最後でHerokuにデプロイできず苦戦したので、その時のメモです。

$ git heroku push master

Herokuにデプロイしようとすると、このようなエラーが出ました。

remote:  !     Precompiling assets failed.
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
remote: !   Push rejected

このような警告が出ていたものの、結果的には、Bundlerのバージョンの違いは特に問題なかったようです。

remote:        Warning: the running version of Bundler (1.15.2) is older than the version that created the lockfile (1.16.1). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
remote:        The latest bundler is 1.16.1, but you are currently running 1.15.2.

問題となっていたのはこの箇所

remote: -----> Detecting rake tasks
remote: -----> Preparing app for Rails asset pipeline
remote:        Running: rake assets:precompile
remote:        rake aborted!
remote:        LoadError: cannot load such file -- fog

「リスト 13.58: GemfileにCarrierWaveを追加する」でGemファイルのバージョンを指定せずに最新版を使ってしまったことが原因だったようです。

gem 'carrierwave',             '1.1.0'
gem 'mini_magick',             '4.7.0'
gem 'fog-aws',                 '2.0.0'

新しいバージョンで利用する際には、
CarrierWaveのGitHubにあるように、以下のように設定して解決できました。

# Gemfile
gem 'fog-aws', group: :production
gem 'carrierwave', '~> 1.0'


# config/initializers/carrierwave.rb
require 'carrierwave/storage/abstract'
require 'carrierwave/storage/file'
require 'carrierwave/storage/fog'

CarrierWave.configure do |config|
  if Rails.env.production?
    config.storage :fog
    config.fog_provider = 'fog/aws'
    config.fog_credentials = {
      provider:              'AWS',
      [...]
    }
    [...]
  else
    config.storage :file
    config.enable_processing = false if Rails.env.test?
  end
end

参考:https://github.com/carrierwaveuploader/carrierwave/issues/1648

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2