【发布时间】: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