igor-alexandrov/paperclip-aws — Issue #5: undefined method `gsub' for nil:NilClass in fresh app
Author: ccheaton
Created: 2011-12-06 03:32:42+00:00
State: open

I'm trying to use `paperclip-aws` 1.4.0 after successfully using vanilla Paperclip during development of a prototype. My model file looks like this:

````ruby
class Image < ActiveRecord::Base
attr_accessible :profile_pic,
:caption,
:note,
:pic_file_name,
:pic_content_type,
:pic_file_size,
:pic_updated_at,
:pic,
:pic_attributes

belongs_to :imageable, :polymorphic => true

# Added for paperclip-aws
def self.s3_config
@@s3_config ||= YAML.load(ERB.new(File.read("#{Rails.root}/config/s3.yml")).result)[Rails.env]
end

has_attached_file :pic,
:styles => {
:large => "500x500>",
:medium => "300x300>",
:thumb => "100x100>",
:tiny => "50>x50>",
:smallest => "24>x24>" },
:default_url => '/:attachment/:style/missing.png',

# Added for paperclip-aws
:storage => :aws,
:s3_credentials => {
:access_key_id => self.s3_config['access_key_id'],
:secret_access_key => self.s3_config['secret_access_key']
},
:bucket => self.s3_config['bucket'],
:s3_permissions => :public_read,
:path => "images/:id/:style/:data_file_name"

# :s3_host_alias => self.s3_config['s3_host_alias'],
# :s3_protocol => 'https',
# :s3_options => {
# :sse => 'AES256',
# :storage_class => :reduced_redundancy,
# :content_disposition => 'attachment'
# },
end
````

For reference, my `s3.yml` file looks like this:

````yaml
development:
access_key_id: my_key
secret_access_key: my_secret_key
bucket: my-dev-bucket
production:
access_key_id: my_key
secret_access_key: my_secret_key
bucket: my-prod-bucket
````

I get the error:

````
`undefined method `gsub' for nil:NilClass` when I try to visit a page that defaults to the `missing.png` file.

Extracted source (around line #33):

30:

Your profile picture

31:

This is how your profile picture will appear when you leave comments on other people's profiles.

32:

33: <%=image_tag current_user.image.pic(:thumb), :class => "profile_image" %>
34:

35:

36: <%= f.fields_for :image do |f| %>

... first part of the trace:
activesupport (3.1.3) lib/active_support/whiny_nil.rb:48:in `method_missing'
paperclip (2.4.5) lib/paperclip/interpolations.rb:33:in `block in interpolate'
paperclip (2.4.5) lib/paperclip/interpolations.rb:32:in `each'
paperclip (2.4.5) lib/paperclip/interpolations.rb:32:in `inject'
paperclip (2.4.5) lib/paperclip/interpolations.rb:32:in `interpolate'
paperclip (2.4.5) lib/paperclip/attachment.rb:439:in `interpolate'
paperclip-aws (1.4.0) lib/paperclip-aws.rb:70:in `url'
paperclip (2.4.5) lib/paperclip/attachment.rb:153:in `to_s'
paperclip (2.4.5) lib/paperclip.rb:333:in `block in has_attached_file'

````

I tried a simpler yaml file that looked like this:

````yaml
access_key_id: my_key
secret_access_key: my_secret_key
bucket: my-prod-bucket
````

The error that appears then is:

````
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.[]
````

Any idea what's going on here? Is this a reemergence of the error thrown for a default image or a problem with my code?