I'm stuck. I'm using carrierwave/fog to implement a simple image upload system. Here is my uploader:
class OfficeImagesUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
include CarrierWave::RMagick
# include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
# storage :file
storage :fog
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
Here is my fog_init:
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS', # required
:aws_access_key_id => ENV['AWSKEY'], # required
:aws_secret_access_key => ENV['AWSSEC'], # required
:region => 'us-east-1' # optional, defaults to 'us-east-1'
}
# config.fog_directory = 'temp-cm' # required
config.fog_public = false # optional, defaults to true
# config.fog_attributes = {'Cache-Control'=>'max-age=315576000'} # optional, defaults to {}
# config.asset_host = 'https://assets.example.com' # optional, defaults to nil
end
CarrierWave.configure {|config| config.fog_directory = 'office-classifieds-development'} if Rails.env.development?
CarrierWave.configure {|config| config.fog_directory = 'office-classifieds-test'} if Rails.env.test?
CarrierWave.configure {|config| config.fog_directory = 'office-classifieds-production'} if Rails.env.production?
And here is the image model to which I want to upload images:
class Image < ActiveRecord::Base
attr_accessible :office_listing_id, :image, :remote_image_url
belongs_to :office_listing
mount_uploader :image, OfficeImagesUploader
end
I encounter two problems. When I try to create an image by doing
Image.create(image: 'someurl.jpg')
the image is not created, the image attribute is never filled in with a url, and I get this error: "can't convert nil into string."
This kinda makes sense, I assume I'm running into errors because :image is meant to be an uploaded file. However, when I try the same thing but substitute remote_image_url for image, I get this error:
undefined method `defaults' for Excon:Module
I have NO idea what this means. Thoughts?