I'm having issue with paperclip and heroku and really need help.I've lost the past 2 days getting stuck on this and none of the link i could found helped :
https://github.com/igor-alexandrov/paperclip-aws"
"http://www.codeitive.com/0QHVXqkUVV/heroku-paperclip-s3-error-%3E- awss3errorssignaturedoesnotmatch.html"
"https://devcenter.heroku.com/articles/paperclip-s3#international-users-additional-configuration"
"http://dchua.com/2011/12/27/how-to-get-paperclip-and-aws-s3-singapore-and-european-buckets-working/"
"http://www.kahfei.com/?p=389"
"http://www.conandalton.net/2011/02/paperclip-s3-and-european-buckets.html"
"http://stackoverflow.com/questions/20424724/ruby-on-rails-paperclip-amazon-aws-s3-heroku"
"http://stackoverflow.com/questions/7257745/rails-3-amazon-s3-paperclip-eu-problem"
In the beginning i wanted to use an european S3 location but since it seems to make everything more complicated i've decided to switch back to the default US location.
I've setup my VARS as follow on terminal :
$ heroku config:set S3_BUCKET_NAME=your_bucket_name
$ heroku config:set AWS_ACCESS_KEY_ID=your_access_key_id
$ heroku config:set AWS_SECRET_ACCESS_KEY=your_secret_access_key
Then inside my config/environment/production.rb :
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']
}
}
When going to my website and trying to upload a picture my heroku log is as follow :
Running `bundle exec rake db:seed` attached to terminal... up, run.8070
rake aborted!
AWS::S3::Errors::SignatureDoesNotMatch: The request signature we calculated does not match the signature you provided. Check your key and signing method.
/app/vendor/bundle/ruby/2.0.0/gems/aws-sdk-v1-1.64.0/lib/aws/core/client.rb:375:in `return_or_raise'
/app/vendor/bundle/ruby/2.0.0/gems/aws-sdk-v1-1.64.0/lib/aws/core/client.rb:476:in `client_request'
(eval):3:in `put_object'
/app/vendor/bundle/ruby/2.0.0/gems/aws-sdk-v1-1.64.0/lib/aws/s3/s3_object.rb:1765:in `write_with_put_object'
/app/vendor/bundle/ruby/2.0.0/gems/aws-sdk-v1-1.64.0/lib/aws/s3/s3_object.rb:611:in `write'
/app/vendor/bundle/ruby/2.0.0/gems/paperclip-4.2.1/lib/paperclip/storage/s3.rb:360:in `block in flush_writes'
/app/vendor/bundle/ruby/2.0.0/gems/paperclip-4.2.1/lib/paperclip/storage/s3.rb:331:in `each'
/app/vendor/bundle/ruby/2.0.0/gems/paperclip-4.2.1/lib/paperclip/storage/s3.rb:331:in `flush_writes'
/app/vendor/bundle/ruby/2.0.0/gems/paperclip-4.2.1/lib/paperclip/attachment.rb:238:in `save'
/app/vendor/bundle/ruby/2.0.0/gems/paperclip-meta-1.2.0/lib/paperclip-meta/attachment.rb:16:in `save_with_meta_data'
/app/vendor/bundle/ruby/2.0.0/gems/paperclip-4.2.1/lib/paperclip/has_attached_file.rb:91:in `block in add_active_record_callbacks'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:441:in `instance_exec'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:441:in `block in make_lambda'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:225:in `call'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:225:in `block in halting_and_conditional'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:92:in `call'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:92:in `_run_callbacks'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:734:in `_run_save_callbacks'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/callbacks.rb:302:in `create_or_update'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/persistence.rb:142:in `save!'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/validations.rb:43:in `save!'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/attribute_methods/dirty.rb:29:in `save!'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/transactions.rb:291:in `block in save!'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/transactions.rb:347:in `block in with_transaction_returning_status'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/transactions.rb:220:in `transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/transactions.rb:344:in `with_transaction_returning_status'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/transactions.rb:291:in `save!'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/persistence.rb:51:in `create!'
/app/db/seeds.rb:9:in `<top (required)>'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `block in load'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/engine.rb:547:in `load_seed'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:250:in `load_seed'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:180:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:seed
Obviously i've double checked my heroku configs and trying to input both key and bucket again => no change.
At this point i've tried so many stuff that i'm at lost.
Setting heroku stuff inside my model after attached_files
Setting heroku YAML file in addition to heroku config var
Tried both european and us standard buckets
If anyone has any idea.. All the research i did on that error didn't help one bit : AWS::S3::Errors::SignatureDoesNotMatch: The request signature we calculated does not match the signature you provided. Check your key and signing method.
Ok just go it working so for the next person having that issue :
-Don't follow the heroku paperclip tutorial
-Create a aws.yml file in your config folder with inside :
development:
access_key_id: "xxxxxinquote"
secret_access_key: "yyyyyinquote"
test:
access_key_id: abc...
secret_access_key: abc...
production:
access_key_id: "xxx"
secret_access_key: "yyyy"
-Inside all your models with file upload put :
has_attached_file :image,
:styles => { :medium => "460x>", :thumb => "100x100>",:vnice=> "400x" },
:storage => :s3,
:bucket => 'hohohohoho',
:s3_credentials => "#{Rails.root}/config/aws.yml",
:path => "resources/:id/:style/:basename.:extension
Then inside your production or/and dev.rb
config.paperclip_defaults = {
:storage => :s3,
:bucket => ENV['S3_BUCKET_NAME'],
:s3_credentials => {
:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
}
}
Note : :bucket is OUTSIDE the s3 credentials unlike what is said in the tutorial.
Hope it can help someone
Related
I'm using fog gem with carrierwave for uploading files to s3. The upload is ok and works perfectly, but, once I try to delete some instance of my model with the file attached, it sends the delete request and returns Access Denied, as bellow:
[fog][WARNING] fog: followed redirect to bucket-name.s3-us-west-2.amazonaws.com, connecting to the matching region will be more performant
Excon::Error::Forbidden: Expected(204) <=> Actual(403 Forbidden)
excon.error.response
:body => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>EB625F4C97AD368E</RequestId><HostId>E+We/GvBslMHoNn9nTT6Uw3t0qfJ9jXHCNkJRu0KOk5sk8WoFZbkaIyUB0WcWNPZuH2uCeoZTIo=</HostId></Error>"
:cookies => [
]
:headers => {
"Content-Type" => "application/xml"
"Date" => "Wed, 21 Dec 2016 14:48:53 GMT"
"Server" => "AmazonS3"
"x-amz-id-2" => "E+We/GvBslMHoNn9nTT6Uw3t0qfJ9jXHCNkJRu0KOk5sk8WoFZbkaIyUB0WcWNPZuH2uCeoZTIo="
"x-amz-request-id" => "EB625F4C97AD368E"
}
:host => "bucket-name.s3.amazonaws.com"
:local_address => "192.168.2.106"
:local_port => 51425
:path => "/uploads/conta/pdf_conta/375/1530_09-2016.pdf"
:port => 443
:reason_phrase => "Forbidden"
:remote_ip => "52.216.66.16"
:status => 403
:status_line => "HTTP/1.1 403 Forbidden\r\n"
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/excon-0.54.0/lib/excon/middlewares/expects.rb:7:in `response_call'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/excon-0.54.0/lib/excon/middlewares/response_parser.rb:9:in `response_call'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/excon-0.54.0/lib/excon/connection.rb:388:in `response'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/excon-0.54.0/lib/excon/connection.rb:252:in `request'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/excon-0.54.0/lib/excon/middlewares/idempotent.rb:27:in `error_call'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/excon-0.54.0/lib/excon/middlewares/base.rb:11:in `error_call'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/excon-0.54.0/lib/excon/middlewares/base.rb:11:in `error_call'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/excon-0.54.0/lib/excon/connection.rb:272:in `rescue in request'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/excon-0.54.0/lib/excon/connection.rb:215:in `request'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/excon-0.54.0/lib/excon/middlewares/idempotent.rb:27:in `error_call'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/excon-0.54.0/lib/excon/middlewares/base.rb:11:in `error_call'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/excon-0.54.0/lib/excon/middlewares/base.rb:11:in `error_call'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/excon-0.54.0/lib/excon/connection.rb:272:in `rescue in request'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/excon-0.54.0/lib/excon/connection.rb:215:in `request'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/excon-0.54.0/lib/excon/middlewares/idempotent.rb:27:in `error_call'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/excon-0.54.0/lib/excon/middlewares/base.rb:11:in `error_call'
... 36 levels...
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands/console_helper.rb:9:in `start'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:78:in `console'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in `<top (required)>'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `block in require'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
from /home/ronanlopes/HY Brazil/HyBrazil/bin/rails:9:in `<top (required)>'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `block in load'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'
from /home/ronanlopes/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /home/ronanlopes/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'
The user token I'm using on my config has the AmazonS3FullAccess - AWS Managed policy, so it doesn't makes sense to me. Any ideas?
From what I see, you are setting the bucket_name variable on fog gem to be 'bucket-name', either that or you have edited it to post here.
Your config/initializer/carrierwave.rb should look something like this
CarrierWave.configure do |config|
config.fog_credentials = {
# Configuration for Amazon S3 should be made available through an Environment variable.
# For local installations, export the env variable through the shell OR
# if using Passenger, set an Apache environment variable.
#
# In Heroku, follow http://devcenter.heroku.com/articles/config-vars
#
# $ heroku config:add S3_KEY=your_s3_access_key S3_SECRET=your_s3_secret S3_REGION=eu-west-1 S3_ASSET_URL=http://assets.example.com/ S3_BUCKET_NAME=s3_bucket/folder
# Configuration for Amazon S3
:provider => 'AWS',
:aws_access_key_id => ENV['S3_KEY'],
:aws_secret_access_key => ENV['S3_SECRET'],
:region => ENV['S3_REGION']
}
# For testing, upload files to local `tmp` folder.
if Rails.env.test? || Rails.env.cucumber?
config.storage = :file
config.enable_processing = false
config.root = "#{Rails.root}/tmp"
else
config.storage = :fog
end
config.cache_dir = "#{Rails.root}/tmp/uploads" # To let CarrierWave work on heroku
config.fog_directory = ENV['S3_BUCKET_NAME']
config.s3_access_policy = :public_read # Generate http:// urls. Defaults to :authenticated_read (https://)
config.fog_host = "#{ENV['S3_ASSET_URL']}/#{ENV['S3_BUCKET_NAME']}"
end
You may be setting ENV['S3_BUCKET_NAME'] or ENV['S3_ASSET_URL'] variables wrong, or even setting it mannually, check those in your .env file
I'm using a Paperclip and Fog to work with cloud storage. Cloud storage provides Openstack API, and here is my setup:
paperclip_defaults.rb:
Paperclip::Attachment.default_options.update({
:path => "images/:class/:id/:attachment/:style/img_:fingerprint",
:storage => :fog,
:fog_credentials => {
:provider => 'OpenStack',
:openstack_auth_url => 'myurl',
:openstack_username => 'login',
:openstack_api_key => 'pass'
},
:fog_directory => 'dir',
:fog_public => true,
})
Everything works fine for upload, but I can't download a picture!
Here is stacktrace:
fog (1.23.0) lib/fog/openstack/models/storage/directory.rb:35:in `public_url'
fog (1.23.0) lib/fog/openstack/models/storage/files.rb:67:in `get_url'
fog (1.23.0) lib/fog/openstack/models/storage/file.rb:81:in `public_url'
paperclip (4.2.0) lib/paperclip/storage/fog.rb:136:in `public_url'
paperclip (4.2.0) lib/paperclip/storage/fog.rb:51:in `block (2 levels) in extended'
paperclip (4.2.0) lib/paperclip/interpolations.rb:34:in `block (2 levels) in interpolate'
paperclip (4.2.0) lib/paperclip/interpolations.rb:33:in `gsub'
paperclip (4.2.0) lib/paperclip/interpolations.rb:33:in `block in interpolate'
paperclip (4.2.0) lib/paperclip/interpolations.rb:32:in `each'
paperclip (4.2.0) lib/paperclip/interpolations.rb:32:in `inject'
paperclip (4.2.0) lib/paperclip/interpolations.rb:32:in `interpolate'
paperclip (4.2.0) lib/paperclip/url_generator.rb:13:in `for'
paperclip (4.2.0) lib/paperclip/attachment.rb:142:in `url'
NotImplementedError
public_url always returns this error for openstack storage. What's wrong?
You need to set "fog_host" to your object storage service endpoint.
Here is an example.
https://gist.github.com/withhawaii/4527bfdbe4fd1d52f67a
You can find your endpoint in Openstack Horizon.
Login to Horizon and click "Access & Security" => "API Access".
You will find the URL for Object Storage service endpoint.
It's basically an URL, where your users can access files.
Your system administrator may set up a proxy or something.
If that's the case, set the URL your system administrator gave to you.
Hope this will help.
GT
I'm not new to DynamoDB, but I'm new to DynamoID gem.
I can't achieve to make it work since I get the following error :
/aws-sdk-1.28.1/lib/aws/core/client.rb:366:in `return_or_raise': The action or operation requested is invalid. Verify that the action is typed correctly. (AWS::DynamoDB::Errors::InvalidAction)
/aws-sdk-1.28.1/lib/aws/core/client.rb:467:in `client_request'
(eval):3:in `list_tables'
/aws-sdk-1.28.1/lib/aws/dynamo_db/table_collection.rb:121:in `_each_item'
/aws-sdk-1.28.1/lib/aws/core/collection/with_limit_and_next_token.rb:54:in `_each_batch'
/aws-sdk-1.28.1/lib/aws/core/collection.rb:80:in `each_batch'
/aws-sdk-1.28.1/lib/aws/core/collection.rb:47:in `each'
/dynamoid-0.7.1/lib/dynamoid/adapter/aws_sdk.rb:185:in `collect'
/dynamoid-0.7.1/lib/dynamoid/adapter/aws_sdk.rb:185:in `list_tables'
/dynamoid-0.7.1/lib/dynamoid/adapter.rb:146:in `block (3 levels) in <module:Adapter>'
/dynamoid-0.7.1/lib/dynamoid/adapter.rb:39:in `benchmark'
/dynamoid-0.7.1/lib/dynamoid/adapter.rb:146:in `block (2 levels) in <module:Adapter>'
/dynamoid-0.7.1/lib/dynamoid/adapter.rb:25:in `block in reconnect!'
/dynamoid-0.7.1/lib/dynamoid/adapter.rb:39:in `benchmark'
/dynamoid-0.7.1/lib/dynamoid/adapter.rb:25:in `reconnect!'
/dynamoid-0.7.1/lib/dynamoid.rb:35:in `configure'
app/config/initializers/dynamoid.rb:1:in `<top (required)>'
It seems that list_tables doesn't exist, but it's a method of the AWS Ruby SDK
My model is very simple :
class Interaction
include Dynamoid::Document
table :name => :interactions, :key => :from, :read_capacity => 1, :write_capacity => 1
end
Could anybody help?
Cheers,
Emmanuel
I have my S3 account set up in Rails 3 like so:
AWS::S3::DEFAULT_HOST.replace "s3-eu-west-1.amazonaws.com"
#Set up AWS S3
AWS::S3::Base.establish_connection!(
:access_key_id => 'itsa',
:secret_access_key => 'secret'
)
BUCKET='wetten'
But for some reason it says that my files do not exist. I have given 'Everyone' Open/Download permissions on the files in S3.
In the Rails console, for this file:
>> AWS::S3::S3Object.exists?('/xml/BWBR0001821.xml', 'wetten')
true
>> AWS::S3::S3Object.find('/xml/BWBR0001821.xml', 'wetten')
AWS::S3::NoSuchKey: No such key `/xml/BWBR0001821.xml'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/aws-s3-0.6.3/lib/aws/s3/object.rb:177:in `find'
from (irb):11
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/commands/console.rb:47:in `start'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/commands/console.rb:8:in `start'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/commands.rb:41:in `<top (required)>'
from C:/Users/Maarten/RubymineProjects/wetten-api/script/rails:6:in `require'
from C:/Users/Maarten/RubymineProjects/wetten-api/script/rails:6:in `<top (required)>'
from -e:1:in `load'
from -e:1:in `<main>'
What's wrong?
UPDATE: I noticed that in object.rb, the AWS S3 gem (v0.6.3) does the following:
bucket = Bucket.find(bucket_name(bucket), :marker => key.previous, :max_keys => 1)
where key is '/xml/BWBR0001821.xml', and key.previous is '/xml/BWBR0001821.xmk'... What the hell? This seems like a bug to me.
Found the error. Apparently, the find method gets confused when by the first forward slash. Using xml/BWBR0001821.xml as a file name works:
>> AWS::S3::S3Object.find('xml/BWBR0001821.xml', 'wetten')
#<AWS::S3::S3Object:0x49387284 '/wetten/xml/BWBR0001821.xml'>
I am beginning to write tests for an application and I'm having trouble getting the test environment to work.
My system has Paperclip for file uploads and it's tripping up at any attempt to start the server or even to initialize a new company record! An example:
# Company.rb line 3
has_attached_file :photo,
:styles => {:medium => "200x300>", :thumb => "100x150>" },
:storage => :s3,
:s3_credentials => "#{::Rails.root.to_s}/config/s3.yml",
:path => "/photos/:style/:id/:basename.:extension"
# console
ruby-1.9.2-p0 :001 > Company.new
NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.[]=
from /Users/san/Documents/san/app/vendor/plugins/paperclip/lib/paperclip.rb:232:in 'has_attached_file'
from /Users/san/Documents/san/app/app/models/company.rb:3:in '<class:company>'
from /Users/san/Documents/san/app/app/models/company.rb:1:in '<top (required)>'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:454:in 'load'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:454:in 'block in load_file'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:591:in 'new_constants_in'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:453:in 'load_file'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:340:in 'require_or_load'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:491:in 'load_missing_constant'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:183:in 'block in const_missing'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:181:in 'each'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:181:in 'const_missing'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in 'const_missing_from_s3_library'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.2/lib/rake/ext/module.rb:36:in 'const_missing'
from (irb):1
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.1/lib/rails/commands/console.rb:44:in 'start'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.1/lib/rails/commands/console.rb:8:in 'start'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.1/lib/rails/commands.rb:23:in '<top (required)>'
from script/rails:6:in 'require'
Do you know what's causing this conflict and how I can fix it?
I read through the Paperclip docs and I discovered the need to add:
require 'paperclip/matchers'
Spec::Runner.configure do |config|
config.include Paperclip::Shoulda::Matchers
end
to spec_helper.rb. Still getting the same error!
I reckon what that is is the s3.yml doesn't contain a key for your current Rails environment, probably test? Add one. That should fix it!
In the end the error was fixed by downgrading Paperclip to 2.3.6, which is what I was using up until a week ago. Hopefully this is helpful to anyone experiencing this error in the future!