2014-07-12 3 views
0

제품을 만들 때 Paperclip gem, paperclip-dropbox gem, figaro gem 및 보관 용을 사용하여 이미지를 업로드하고 저장합니다. 개발 중에는 이미지 파일이 데이터베이스에 잘 업로드되어 표시되지만 생산시에는 이미지가 Dropbox로 이동한다고 가정 할 때 양식이 통과하지 않고 볼 때 Dropbox 인증 오류가 발생합니다 내 Heroku 로그. Dropbox 보안 키가 모두 정확한지 확인했습니다. 나는 관련된 모든 질문을 살펴 봤는데 아무 것도 찾을 수 없다.레일 4 - 종이 클립 - 보관 용구 문제

:

다음
# 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의 끝에 PARAMS입니다 : 여기

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의 # 만들기 작업입니다 : 여기

는 Heroku가에서 오류가
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 %> 

답변

0

가에 대해 Heroku가 이야기의 매우 중요한 단계를 잊지 마세요를 이 방법을 사용하는 경우 피가로 보석.

rake figaro:heroku 

나를 위해 속임수를 사용했습니다. gem page now을 보면, 나는 그 명령을 보지 못할 것이다. 그러나보고자하는 Heroku에 배치하는 부분이있다.

0

나는 비슷한 문제가있어서 개발 환경에서 생산 환경으로 환경을 바꿔야 만했다.

class Listing < ActiveRecord::Base 
    if Rails.env.production? 
    has_attached_file :image, 
    :styles => { :medium => "200x", :thumb => "100x100>" }, :default_url => "default.jpg", 
    :storage => :dropbox, 
    :dropbox_credentials => Rails.root.join("config/dropbox.yml"), 
:path => ":style/:id_:filename" 
    validates_attachment_content_type :image, :content_type => %w(image/jpeg image/jpg image/png) 
    else 
    has_attached_file :image, 
    :styles => { :medium => "200x", :thumb => "100x100>" }, :default_url => "default.jpg" 
    end 
end 

생산 대신 개발이 지정되었지만 적어도 후자가 작동 할 때 왜 작동하지 않는지는 알 수 없습니다.

0

답변이 늦을 지 모르지만 누군가 도움이 될 수 있습니다.

Dropbox의 개발자 콘솔에서 'Development user' 설정을 변경하면 작동합니다. 처음에 앱을 만들 때 'Development users''Only you'이됩니다.

'추가 사용자 사용'버튼을 클릭하면 더 많은 사용자가 앱에 액세스 할 수 있습니다.

관련 문제