简体   繁体   中英

CarrierWave and Google Cloud Storage error: `require': cannot load such file — net/ssh (LoadError)

After following all the best practices of posting questions on here, I am told that I can not post more than 2 links... (which is very counter intuitive since it contradicts their best practises...). Anyway :)

The links are in this pastebin .

I am trying to use CarrierWave to upload files to Google Cloud Storage and I am running into crippling problems before I even get to the file handling stage.

This question was asked before about Amazon S3 and it yielded answers that did not fix my problem. The issue has been brought up before on carrierwave's GitHub page. (link 5)

I followed this tutorial (link 1), double checked with the official CarrierWave documentation for uploads to Google Cloud Storage (Link 2) and also consulted this post (Link 3) which discusses the initialization of settings (which was way beyond me).

The exact problem I have is that the line storage :fog in my FileUploader class causes a NameError in UploadsController#index . The full error page is shown here. (link 4) The issue is that carrierwave doesn't recognize the storage :fog configuration in the uploader class. For some reason it is uninitialized, despite the initilaizer I included in config/initializers .

If I add the fog gem, the rails server refuses to start with the following message:

/home/username/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/fog-1.35.0/lib/fog/joyent/compute.rb:3:in 'require': cannot load such file -- net/ssh (LoadError)

My code is as follows

config/initializers/carrierwave.rb

#require 'fog' # causes error
# require 'rails' --> removed this line, as suggested by Simone.
require 'carrierwave'


CarrierWave.configure do |config|
  config.root = Rails.root.join('tmp')
  #config.fog_provider = 'fog-google' # removed this line as well, suggested by Simone
  config.cache_dir = 'carrierwave'

  config.fog_credentials = {
      :provider => 'Google',
      :google_storage_access_key_id => 'xxxx',
      :google_storage_secret_access_key => 'yyyy'
  }
  config.fog_directory = 'pdf_uploads'

end

app/uploaders/file_uploader.rb

# encoding: utf-8

class FileUploader < CarrierWave::Uploader::Base

  storage :fog #causes the NameError

  def store_dir
     "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
    #"pdf_uploads/#{model.id}"
  end
end

app/models/upload.rb

class Upload < ActiveRecord::Base
    mount_uploader :file, FileUploader
    #other code omitted
end

** Gemfile **

gem 'carrierwave', '~> 0.10.0'
gem 'fog-google', '~> 0.1.1' #in this order

I spend hours last night (until 2 am) trying to figure this out by myself. I don't normally post on here because im a very patient debugger but this is beyond me because I followed all the tutorials exactly.

Try changing this line:

config.fog_provider = 'fog-google'

To this:

config.fog_provider = 'fog/google'

I ran into the same problem since the docs on Carrierwave aren't correct. I think fog-google is eventually how the provider will be defined, but as of version 0.1.1 this is working for me.

As described in this issue , you don't need to use fog_provider if you already have a provider key in the fog_credentials hash.

You are probably reading a documentation for a different version.

Also, the following line in the initializer doesn't make sense, please remove it

require 'rails'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM