title: Paperclip on S3 not working
body: <p>I'm trying to use Paperclip with Amazon S3 on my Rails 4.2.3 app.</p>
  
  <p>Everything works fine if I use Paperclip storing data locally on my machine.
  Problems are when I try to use Paperclip storing files on S3.</p>
  
  <p>For example, simply trying to create a new User instance fires an error:</p>
  
  <pre><code>u = User.new
  u.name = "Mark"
  u.save
  NoMethodError: undefined method `new' for nil:NilClass
      from /Users/Augusto/.rvm/gems/ruby-2.2.4/gems/paperclip-4.3.6/lib/paperclip/attachment.rb:84:in `initialize'
      from /Users/Augusto/.rvm/gems/ruby-2.2.4/gems/paperclip-4.3.6/lib/paperclip/has_attached_file.rb:47:in `new'
      from /Users/Augusto/.rvm/gems/ruby-2.2.4/gems/paperclip-4.3.6/lib/paperclip/has_attached_file.rb:47:in `block in define_instance_getter'
      from /Users/Augusto/.rvm/gems/ruby-2.2.4/gems/activemodel-4.2.6/lib/active_model/validator.rb:149:in `block in validate'
      from /Users/Augusto/.rvm/gems/ruby-2.2.4/gems/activemodel-4.2.6/lib/active_model/validator.rb:148:in `each'
      from /Users/Augusto/.rvm/gems/ruby-2.2.4/gems/activemodel-4.2.6/lib/active_model/validator.rb:148:in `validate'
      from /Users/Augusto/.rvm/gems/ruby-2.2.4/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:455:in `public_send'
      from /Users/Augusto/.rvm/gems/ruby-2.2.4/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:455:in `block in make_lambda'
      from /Users/Augusto/.rvm/gems/ruby-2.2.4/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:192:in `call'
      from /Users/Augusto/.rvm/gems/ruby-2.2.4/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:192:in `block in simple'
      from /Users/Augusto/.rvm/gems/ruby-2.2.4/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:504:in `call'
      from /Users/Augusto/.rvm/gems/ruby-2.2.4/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:504:in `block in call'
      from /Users/Augusto/.rvm/gems/ruby-2.2.4/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:504:in `each'
      from /Users/Augusto/.rvm/gems/ruby-2.2.4/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:504:in `call'
      from /Users/Augusto/.rvm/gems/ruby-2.2.4/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:92:in `__run_callbacks__'
      from /Users/Augusto/.rvm/gems/ruby-2.2.4/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:778:in `_run_validate_callbacks'
  ... 22 levels...
      from /Users/Augusto/.rvm/gems/ruby-2.2.4/gems/railties-4.2.6/lib/rails/commands/console.rb:9:in `start'
      from /Users/Augusto/.rvm/gems/ruby-2.2.4/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:68:in `console'
      from /Users/Augusto/.rvm/gems/ruby-2.2.4/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
      from /Users/Augusto/.rvm/gems/ruby-2.2.4/gems/railties-4.2.6/lib/rails/commands.rb:17:in `&lt;top (required)&gt;'
      from /Users/Augusto/.rvm/gems/ruby-2.2.4/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require'
      from /Users/Augusto/.rvm/gems/ruby-2.2.4/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `block in require'
      from /Users/Augusto/.rvm/gems/ruby-2.2.4/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:240:in `load_dependency'
      from /Users/Augusto/.rvm/gems/ruby-2.2.4/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require'
      from /Users/Augusto/Sites/ccu_test/bin/rails:9:in `&lt;top (required)&gt;'
      from /Users/Augusto/.rvm/gems/ruby-2.2.4/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:268:in `load'
      from /Users/Augusto/.rvm/gems/ruby-2.2.4/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:268:in `block in load'
      from /Users/Augusto/.rvm/gems/ruby-2.2.4/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:240:in `load_dependency'
      from /Users/Augusto/.rvm/gems/ruby-2.2.4/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:268:in `load'
      from /Users/Augusto/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
      from /Users/Augusto/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
  </code></pre>
  
  <p>My Gemfile:</p>
  
  <pre><code>source 'https://rubygems.org'
  gem 'rails', '4.2.6'
  gem "pg"
  gem 'aws-sdk', '~&gt; 2.3'
  gem "paperclip", '~&gt; 4.3.6'
  gem 'sass-rails', '~&gt; 5.0'
  gem 'uglifier', '&gt;= 1.3.0'
  gem 'jquery-rails'
  gem 'jbuilder', '~&gt; 2.0'
  </code></pre>
  
  <p>I've installed ImageMagik and added to my development.rb</p>
  
  <pre><code>Paperclip.options[:command_path] = "/usr/local/bin/"
  </code></pre>
  
  <p>My model:</p>
  
  <p>user.rb</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
      has_attached_file :avatar, :styles =&gt; {:micro =&gt; "32x32#", :thumb =&gt; "50x50#", :big_thumb =&gt; "80x80#", :small =&gt; "220x220&gt;", :featured =&gt; "220x220#", :medium =&gt; "600x600&gt;"}#, :default_url =&gt; 'http://s3.amazonaws.com/ccu-static/file.small.png'
  end
  </code></pre>
  
  <p>config > initializers > paperclip_defaults.rb</p>
  
  <pre><code>module Paperclip
    class Attachment
      def self.default_options
        @default_options ||= {
          :storage           =&gt; :s3,
          :url               =&gt; "/system/:attachment/:id/:style/:filename",
          :path              =&gt; "/:attachment/:id/:style/:filename",
          :styles            =&gt; {},
          :processors        =&gt; [:thumbnail],
          :convert_options   =&gt; {},
          :default_url       =&gt; "/images/missing.:style.gif", #"http://s3.amazonaws.com/ccu-static/missing.:style.png", 
          :default_style     =&gt; :original,
          :s3_credentials =&gt; "#{Rails.root}/config/s3.yml",
          :whiny             =&gt; Paperclip.options[:whiny] || Paperclip.options[:whiny_thumbnails]
        }
      end
    end
  end
  </code></pre>
  
  <p>config > initializers > aws.rb</p>
  
  <pre><code>Aws.config.update({
    region: 'us-west-2',
    credentials: Aws::Credentials.new('...', '...')
  })
  </code></pre>
  
  <p>config > S3.yml</p>
  
  <pre><code>production:
    bucket: ...
    access_key_id: ...
    secret_access_key: ...
  development:
    bucket: ...
    access_key_id: ...
    secret_access_key: ...
  </code></pre>
  
  <p>schema.rb</p>
  
  <pre><code>  create_table "users", force: :cascade do |t|
      ...
      t.string   "name"
      t.string   "avatar_file_name",           limit: 255
      t.integer  "avatar_file_size"
      t.string   "avatar_content_type",        limit: 255
      t.datetime "avatar_updated_at"
    end
  </code></pre>