PostsController中的Excon :: Errors :: SocketError #create

时间:2016-02-19 22:29:49

标签: excon

我正在使用Rails设置照片博客并且遇到此错误: Excon :: Errors :: PostsController中的SocketError #create

通过对等方重置连接(Errno :: ECONNRESET)

摘录的来源(第30行):

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'

这是我的帖子模型:

class Post < ActiveRecord::Base
    validates_presence_of :title, :image

    mount_uploader :image, PhotoUploader
end

这是我的邮政控制员:

class PostsController < 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

上传

# encoding: utf-8

class PhotoUploader < 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 => [200, 200]   #   # def scale(width, height)   #   # do something   # end

  # Create different versions of your uploaded files:   version :tiny do
    process :resize_to_fill => [20, 20]   end

  version :profile_size do
    process :resize_to_fill => [300, 300]   end

  # version :full_size do   #   process :resize_to_fill => [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

Carrierwave config(fog.rb)

CarrierWave.configure do |config|
  config.fog_credentials = {
    :provider               => "AWS",
    :aws_access_key_id      => ENV['AWS_ACCESS_KEY_ID'],
    :aws_secret_access_key  => ENV['AWS_SECRET_ACCESS_KEY']
  }

  config.fog_directory  = ENV['AWS_BUCKET']
  config.fog_public     = false
  config.fog_region     = ENV['AWS_REGION']
end

1 个答案:

答案 0 :(得分:0)

我的地区没有价值。我首先设置了us-west-1,然后返回错误,但是将区域更改为us-east-1。 谢谢Geemus!