【问题标题】:Rails 4 app getting errors uploading via Amazon s3Rails 4 应用程序通过 Amazon s3 上传时出错
【发布时间】:2014-04-26 03:57:28
【问题描述】:

我可以通过回形针 gem 将图像上传到本地主机,但是当我在 heroku 上执行此操作时出现错误

Completed 500 Internal Server Error in 801ms
ArgumentError (missing required :bucket option):
app/controllers/listings_controller.rb:29:in `create'
ArgumentError (missing required :bucket option):
app/controllers/listings_controller.rb:29:in `create'

我运行了 heroku 配置,它显示所有内容都已设置 - 存储桶、ID 和访问密钥并正在查看 在 Amazon s3 - 图像过去已保存,但现在出现错误。

列表控制器

class ListingsController < ApplicationController
  before_action :set_listing, only: [:show, :edit, :update, :destroy]

  # GET /listings
  # GET /listings.json
  def index
    @listings = Listing.all
  end

  # GET /listings/1
  # GET /listings/1.json
  def show
  end

  # GET /listings/new
  def new
    @listing = Listing.new
  end

  # GET /listings/1/edit
  def edit
  end

  # POST /listings
  # POST /listings.json
  def create
    @listing = Listing.new(listing_params)

      if @listing.save
        redirect_to @listing, notice: 'Listing was successfully created.'
      else
        render action: 'new' 
      end
  end


  # PATCH/PUT /listings/1
  # PATCH/PUT /listings/1.json
  def update

      if @listing.update(listing_params)
         redirect_to @listing, notice: 'Listing was successfully updated.'
      else
        render action: 'edit'
      end
  end

  # DELETE /listings/1
  # DELETE /listings/1.json
  def destroy
    @listing.destroy
      redirect_to listings_url
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_listing
      @listing = Listing.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def listing_params
      params.require(:listing).permit(:name, :description, :image)
    end
end

listing.rb

class Listing < ActiveRecord::Base

  has_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100>" }
  validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/

  validates :image, presence: true
  validates :description, presence: true
  validates :name, presence: true

end

配置.生产

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']
  }
}

【问题讨论】:

    标签: ruby-on-rails ruby heroku amazon-web-services amazon-s3


    【解决方案1】:

    您是否在 config 文件夹中创建了 application.yml 文件?这是一个例子:https://github.com/codeprimate/mylibrary/blob/master/config/application.yml.example

    你需要把你的桶信息放在那里。

    【讨论】:

    • 不,我使用 heroku 配置命令将其直接推送到 heroku
    猜你喜欢
    • 1970-01-01
    • 2013-01-12
    • 1970-01-01
    • 2012-05-17
    • 2015-05-11
    • 2015-12-10
    • 1970-01-01
    • 2015-05-30
    • 1970-01-01
    相关资源
    最近更新 更多