LoginSignup
13

More than 5 years have passed since last update.

Rails Tutorial13章のherokuへのデプロイ時に詰まった

Last updated at Posted at 2017-12-19

Rails Tutorialの13章をやっている時、最後のherokuへのデプロイで何故かTutorial通りにやってもできず詰まった。
最初はfogのエラーかと思ったが、CarrierWaveの設定が原因だった。

環境

Mac OS High Sierra 10.13.2
Ruby on Rails 5.1.4
CarrierWave 1.1.0

詰まった点

herokuにデプロイ時に下記エラーメッセージが発生。

LoadError: cannot load such file -- fog

原因

調べてみるとfog自体が悪いというよりはfogを利用する、CarrierWave自体の設定がおかしいらしい。そこでCarrierWaveのReadmeのfogの欄を読んだ。https://github.com/carrierwaveuploader/carrierwave/blob/master/README.md#fog

If you want to use fog you must add in your CarrierWave initializer the following lines
config.fog_provider = 'fog' # 'fog/aws' etc. Defaults to 'fog'

と書いてあり、fogを使うのであれば、initializerにfogの設定をaddしてくださいね、デフォルトは"fog"ですよと書かれている。
さらにその下のUsing Amazon S3の欄をみると
https://github.com/carrierwaveuploader/carrierwave/blob/master/README.md#using-amazon-s3

CarrierWave.configure do |config|
config.fog_provider = 'fog/aws' # required

どうやらRails Tutorialのようにawsを使う場合は、"fog/aws"に変更しなくてはならないらしい。。

解決

最終的に、下記のように設定を変更し、再度git addとcommitを行い、herokuにpushしたらいけた。

config/initializers/carrier_wave.rb
if Rails.env.production?
  CarrierWave.configure do |config|
    config.fog_provider = 'fog/aws' #←ここを追記
    config.fog_credentials = {
      :provider              => 'AWS',
      :region                => ENV['S3_REGION'],
      :aws_access_key_id     => ENV['S3_ACCESS_KEY'],
      :aws_secret_access_key => ENV['S3_SECRET_KEY']
    }
    config.fog_directory     =  ENV['S3_BUCKET']
  end
end

同じように詰まった人の参考になれば。

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
13