【发布时间】:2014-09-03 02:36:45
【问题描述】:
我正在使用Paperclip gem、paperclip-dropbox gem、figaro gem 和 Dropbox 在创建产品时上传和存储图像。在本地,在开发中,图像文件很好地上传到数据库,并且是可见的,但是在生产中,图像应该进入 Dropbox,表单没有通过,并且在查看时出现 Dropbox 身份验证错误在我的 Heroku 日志中。我已经三次检查了我的 Dropbox 安全密钥是否正确。我查看了所有相关问题,但找不到任何可行的方法。
这是heroku的错误:
DropboxAuthError (User is not authenticated.):
2014-07-12T16:04:12.514637+00:00 app[web.1]: app/controllers/products_controller.rb:31:in `block in create'
2014-07-12T16:04:12.514638+00:00 app[web.1]: app/controllers/products_controller.rb:30:in `create'
2014-07-12T16:04:12.514640+00:00 app[web.1]:
2014-07-12T16:04:12.514642+00:00 app[web.1]:
2014-07-12T16:04:12.512474+00:00 app[web.1]: Completed 500 Internal Server Error in 2361ms
这是我的 products_controller #create 操作:
# POST /products
# POST /products.json
def create
@product = Product.new(product_params)
@product.user = current_user
respond_to do |format|
if @product.save
format.html {
redirect_to @product,
notice: 'Product was successfully created.'
}
format.json {
render json: @product,
status: :created,
location: @product
}
else
format.html { render :new }
format.json {
render json: @product.errors,
status: :unprocessable_entity
}
end
end
end
这是 products_create 末尾的参数:
private
def set_product
@product = Product.find(params[:id])
end
def product_params
params.require(:product).permit(:description, :name, :permalink, :price, :file, :user_id)
end
这是我的产品型号:
class Product < ActiveRecord::Base
if Rails.env.development?
has_attached_file :file
else
has_attached_file :file,
:storage => :dropbox,
:dropbox_credentials => Rails.root.join("config/dropbox.yml"),
:path => ":style/:id_:filename"
end
belongs_to :user
has_many :sales
validates_numericality_of :price,
greater_than: 49,
message: "must be at least 50 cents"
validates_attachment_content_type :file, :content_type => %w(image/jpeg image/jpg image/png)
end
最后是创建新产品的表格:
<%= form_for(@product,:html => { :multipart => true }) do |f| %>
<% if @product.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@product.errors.count, "error") %> prohibited this product from being saved:</h2>
<ul>
<% @product.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br>
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :permalink %><br>
<%= f.text_field :permalink %>
</div>
<div class="field">
<%= f.label :description %><br>
<%= f.text_area :description %>
</div>
<div class="field">
<%= f.label :price %><br>
<%= f.number_field :price %>
</div>
<div class="field">
<%= f.label :user_id %><br>
<%= f.text_field :user_id %>
</div>
<div class="field">
<%= f.label :file %><br />
<%= f.file_field :file %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
【问题讨论】:
标签: ruby-on-rails heroku ruby-on-rails-4 paperclip dropbox