0
votes

I am using paperclip to handle image uploads in my Rails app. All works fine running in the development environment locally using the File Storage.

Now I am trying to get this working using S3 (because the app is to run on Heroku). I have set up a bucket and set the appropriate parameters in development.rb and production.rb as per the instructions here: https://devcenter.heroku.com/articles/paperclip-s3

When I start the server, I get the following error:

/Users/ganzogo/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.13/lib/rails/railtie/configuration.rb:85:in `method_missing': undefined method `paperclip' for #<Rails::Application::Configuration:0x007fcb8b952000> (NoMethodError)
  from /Users/ganzogo/Documents/acknowledgement/true-rails/config/environments/development.rb:41:in `block in <top (required)>'

And then it crashes.

The line referred to in the error is:

config.paperclip.defaults = {
  :storage => :s3,
  :s3_credentials => {
    :bucket => ENV['S3_BUCKET_NAME'],
    :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
    :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
  }
}

I get exactly the same error if I try to run on Heroku. Has anyone been through this and have any idea what I have missed?

2
The differences on that post are that they use the 'aws-s3' gem rather than 'aws-sdk', they store their AWS credentials in a .yml file, and they modify the model itself to reference the storage method. I have made all of those changes and I am still getting the same error.ganzogo

2 Answers

3
votes

It looks like you may have a typo in your configuration block. Try changing config.paperclip.defaults = {...} to config.paperclip_defaults = {...} and that should solve your problem.

0
votes

We got this working on one of our live apps

The difference is you need to put the credentials into the model itself. Here's what we've got:


#app/models/image.rb
#Image Upload 
        Paperclip.options[:command_path] = 'C:\RailsInstaller\ImageMagick'
        has_attached_file :image,
                :styles => { :medium => "x300", :thumb => "x100" },
                :default_url => "*******",
                :storage => :s3,
                :bucket => '******',
                :s3_credentials => S3_CREDENTIALS


#app/config/application.rb
config.paperclip_defaults = {
            :storage => :s3,
            :s3_host_name => 's3-eu-west-1.amazonaws.com'
    }

In Heroku, you'll need to add the various environment variables to your config settings