0

I recently linked my Rails App with Amazon S3 so that my users can upload files while I host on Heroku. I followed the tutorial at Firehose Project:

http://blog.thefirehoseproject.com/posts/switching-carrierwave-to-use-s3-with-heroku-and-localhost/

Upon first trying, I got an undefined method error for the following line:

config.fog_provider = 'fog/aws'

(I can revert to an old commit if you think the exact text of that old error would be helpful.)

Poking around about that error, the only solution that worked was to set my version of carrierwave to '1.0.0.beta'. I'm sure that using this version is not ideal, but it's the only one that works so far. Development and production are functional now, but not testing. Every test that includes an uploaded file now throws an extra argument error.

ActionView::Template::Error: wrong number of arguments (given 2, expected 0)

This problem does not happen with most version of carrierwave. But I haven't yet found a combination of gems that will work for all three of my environments.

Thank you in advance for any insight.

# config/initializers/carrierwave.rb

CarrierWave.configure do |config|
  config.fog_provider = 'fog/aws'                        # required
  config.fog_credentials = {
    provider:              'AWS',                        # required
    aws_access_key_id:     ENV["AWS_ACCESS_KEY"],        # required
    aws_secret_access_key: ENV["AWS_SECRET_KEY"],        # required
  }
  config.fog_directory  = ENV["AWS_BUCKET"]              # required
end

Example of an error-throwing code line

<%= link_to image_tag(question.picture.image_url(:thumb).to_s), edit_question_path(question), :id => "schmedit_#{question.id}" %>

Gemfile

source 'https://rubygems.org'

gem 'rails',          '5.0.0'
gem 'bcrypt',         '3.1.11'
gem 'faker',          '1.6.3'
gem 'will_paginate',           '3.1.0'
gem 'bootstrap-will_paginate', '0.0.10'
gem 'bootstrap-sass', '3.3.6'
gem 'puma',           '3.4.0'
gem 'sass-rails',     '5.0.5'
gem 'uglifier',       '3.0.0'
gem 'coffee-rails',   '4.2.1'
gem 'jquery-rails',   '4.1.1'
gem 'jquery-ui-rails'
gem 'turbolinks',     '5.0.0'
gem 'jquery-turbolinks'
gem 'jbuilder',       '2.4.1'
gem 'best_in_place', '~> 3.1'
gem 'responders', '~> 2.2'
gem 'carrierwave', '~> 1.0.0.beta'
gem 'mini_magick', '~> 4.3'
gem 'capybara'
gem 'figaro'
gem 'fog-aws', '0.12.0'

group :development, :test do
  gem 'sqlite3', '1.3.11'
  gem 'byebug',  '9.0.0', platform: :mri
end

group :development do
  gem 'web-console',           '3.1.1'
  gem 'listen',                '3.0.8'
  gem 'spring',                '1.7.1'
  gem 'spring-watcher-listen', '2.0.0'
end

group :test do
  gem 'rails-controller-testing', '0.1.1'
  gem 'minitest-reporters',       '1.1.9'
  gem 'guard',                    '2.13.0'
  gem 'guard-minitest',           '2.4.4'
end

group :production do
  gem 'pg', '0.18.4'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
Jeff Zivkovic
  • 547
  • 1
  • 4
  • 20

1 Answers1

0

This change in the code seems to have fixed the problem:

config.fog_provider = 'fog/aws'

should instead be:

config.fog_directory = 'fog/aws'

in the file config/initializers/carrierwave.rb

Jeff Zivkovic
  • 547
  • 1
  • 4
  • 20