title: Excon::Errors::SocketError in PostsController#create
body: <p>I'm setting up a photo blog with Rails and am having difficulty with this error: <em>Excon::Errors::SocketError in PostsController#create</em> </p>
  
  <p>Connection reset by peer (Errno::ECONNRESET)</p>
  
  <p><strong>Extracted source (around line #30):</strong></p>
  
  <pre><code>respond_to do |format|
    if @post.save
      format.html { redirect_to @post, notice: 'Post was successfully created.' }
      format.json { render :show, status: :created, location: @post }
    else
  
  
  (0.2ms)  BEGIN
    SQL (0.3ms)  INSERT INTO "posts" ("title", "image", "description", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id"  [["title", "Title test"], ["image", "mcm-magnavox-stereo-1.jpg"], ["description", "Description test"], ["created_at", "2016-02-19 22:13:34.023935"], ["updated_at", "2016-02-19 22:13:34.023935"]]
     (0.9ms)  ROLLBACK
  Completed 500 Internal Server Error in 6027ms (ActiveRecord: 1.6ms)
  
  Excon::Errors::SocketError (Connection reset by peer (Errno::ECONNRESET)):
    app/controllers/posts_controller.rb:30:in `block in create'
    app/controllers/posts_controller.rb:29:in `create'
  </code></pre>
  
  <p>Here's my post model:</p>
  
  <pre><code>class Post &lt; ActiveRecord::Base
      validates_presence_of :title, :image
  
      mount_uploader :image, PhotoUploader
  end
  </code></pre>
  
  <p>Here's my post controller:</p>
  
  <pre><code>class PostsController &lt; ApplicationController
    before_action :set_post, only: [:show, :edit, :update, :destroy]
  
    # GET /posts
    # GET /posts.json
    def index
      @posts = Post.all
    end
  
    # GET /posts/1
    # GET /posts/1.json
    def show
    end
  
    # GET /posts/new
    def new
      @post = Post.new
    end
  
    # GET /posts/1/edit
    def edit
    end
  
    # POST /posts
    # POST /posts.json
    def create
      @post = Post.new(post_params)
  
      respond_to do |format|
        if @post.save
          format.html { redirect_to @post, notice: 'Post was successfully created.' }
          format.json { render :show, status: :created, location: @post }
        else
          format.html { render :new }
          format.json { render json: @post.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # PATCH/PUT /posts/1
    # PATCH/PUT /posts/1.json
    def update
      respond_to do |format|
        if @post.update(post_params)
          format.html { redirect_to @post, notice: 'Post was successfully updated.' }
          format.json { render :show, status: :ok, location: @post }
        else
          format.html { render :edit }
          format.json { render json: @post.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # DELETE /posts/1
    # DELETE /posts/1.json
    def destroy
      @post.destroy
      respond_to do |format|
        format.html { redirect_to posts_url, notice: 'Post was successfully destroyed.' }
        format.json { head :no_content }
      end
    end
  
    private
      # Use callbacks to share common setup or constraints between actions.
      def set_post
        @post = Post.find(params[:id])
      end
  
      # Never trust parameters from the scary internet, only allow the white list through.
      def post_params
        params.require(:post).permit(:title, :image, :description)
      end
  end
  </code></pre>
  
  <p>Uploader</p>
  
  <pre><code># encoding: utf-8
  
  class PhotoUploader &lt; CarrierWave::Uploader::Base
  
    # Include RMagick or MiniMagick support:   # include CarrierWave::RMagick   include CarrierWave::MiniMagick
  
    # Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:   # include Sprockets::Helpers::RailsHelper   # include Sprockets::Helpers::IsolatedHelper
  
    # Include the sprockets-rails helper for Rails 4+ asset pipeline compatibility:   include Sprockets::Rails::Helper
  
    # Choose what kind of storage to use for this uploader:   # storage :file   storage :fog
  
    # Override the directory where uploaded files will be stored.   # This is a sensible default for uploaders that are meant to be mounted: def store_dir
      "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"   end
  
    # Provide a default URL as a default if there hasn't been a file uploaded:   # def default_url   #   # For Rails 3.1+ asset pipeline compatibility:   #   # asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))   #   #   "/images/fallback/" + [version_name, "default.png"].compact.join('_')   # end
  
    # Process files as they are uploaded:   #process :resize_to_fill =&gt; [200, 200]   #   # def scale(width, height)   #   # do something   # end
  
    # Create different versions of your uploaded files:   version :tiny do
      process :resize_to_fill =&gt; [20, 20]   end
  
    version :profile_size do
      process :resize_to_fill =&gt; [300, 300]   end
  
    # version :full_size do   #   process :resize_to_fill =&gt; [700, 700] 
  # end
  
    # Add a white list of extensions which are allowed to be uploaded.  
  # For images you might use something like this:   def extension_white_list
      %w(jpg jpeg gif png)   end
  
    # Override the filename of the uploaded files:   # Avoid using model.id or version_name here, see uploader/store.rb for details.   # def filename   #   "something.jpg" if original_filename   # end
  
  end
  </code></pre>
  
  <p>Carrierwave config (fog.rb)</p>
  
  <pre><code>CarrierWave.configure do |config|
    config.fog_credentials = {
      :provider               =&gt; "AWS",
      :aws_access_key_id      =&gt; ENV['AWS_ACCESS_KEY_ID'],
      :aws_secret_access_key  =&gt; ENV['AWS_SECRET_ACCESS_KEY']
    }
  
    config.fog_directory  = ENV['AWS_BUCKET']
    config.fog_public     = false
    config.fog_region     = ENV['AWS_REGION']
  end
  </code></pre>