2012-10-26 38 views
-1

我想使用paperclip-dropbox寶石here,我遇到了設置問題並傳遞了我的憑據。paperclip-dropbox寶石拋出錯誤的參數類型

在文檔,模型的設定可以這樣判定:

class User < ActiveRecord::Base 
    has_attached_file :avatar, 
    :storage => :dropbox, 
    :dropbox_credentials => "#{Rails.root}/config/dropbox.yml", 
    :dropbox_options => {...} 
end 

我已經配置我的dropbox.yml文件放在/ config文件夾,但Rails是告訴我的文件或目錄沒有按不存在。

如果我通過我的憑據與環境變量的散列,

:dropbox_credentials => { 
        app_key: ENV["DROPBOX_APP_KEY"], 
        app_secret: ENV["DROPBOX_APP_SECRET"], 
        access_token: ENV["DROPBOX_ACCESS_TOKEN"], 
        access_token_secret: ENV["DROPBOX_ACCESS_TOKEN_SECRET"], 
        user_id: ENV["DROPBOX_USER_ID"] 
       } 
:dropbox_options => { 
        :path => ":attachment/:id/:basename.:extension" 
       } 

堆棧跟蹤的頂部是:

paperclip-dropbox (1.0.0) lib/paperclip/storage/dropbox.rb:59:in `path_for_url' 
paperclip-dropbox (1.0.0) lib/paperclip/storage/dropbox.rb:55:in `path' 
paperclip-dropbox (1.0.0) lib/paperclip/storage/dropbox.rb:41:in `exists?' 
paperclip (3.2.0) lib/paperclip/attachment.rb:436:in `block in queue_all_for_delete' 
paperclip (3.2.0) lib/paperclip/attachment.rb:435:in `map' 
paperclip (3.2.0) lib/paperclip/attachment.rb:435:in `queue_all_for_delete' 
paperclip (3.2.0) lib/paperclip/attachment.rb:213:in `clear' 
paperclip (3.2.0) lib/paperclip/attachment.rb:94:in `assign' 
paperclip (3.2.0) lib/paperclip.rb:196:in `block in has_attached_file' 
activerecord (3.2.6) lib/active_record/attribute_assignment.rb:85:in `block in  assign_attributes' 
activerecord (3.2.6) lib/active_record/attribute_assignment.rb:78:in `each' 
activerecord (3.2.6) lib/active_record/attribute_assignment.rb:78:in `assign_attributes' 
activerecord (3.2.6) lib/active_record/persistence.rb:212:in `block in update_attributes' 
activerecord (3.2.6) lib/active_record/transactions.rb:295:in `block in with_transaction_returning_status' 
activerecord (3.2.6) lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction' 
activerecord (3.2.6) lib/active_record/transactions.rb:208:in `transaction' 
activerecord (3.2.6) lib/active_record/transactions.rb:293:in `with_transaction_returning_status' 
activerecord (3.2.6) lib/active_record/persistence.rb:211:in `update_attributes' 
app/controllers/users_controller.rb:45:in `update' 

然後導軌說:「錯誤的參數類型爲String預計PROC」

我是新來的紅寶石,不太瞭解特效。我如何解決這個問題讓它起作用?

+0

你在':dropbox_options'中有什麼? –

+0

您能添加錯誤的完整堆棧跟蹤嗎? –

+0

@ZachKemp,我添加了:dropbox_options哈希和堆棧跟蹤。在查看堆棧跟蹤之後,我開始認爲我的問題與我試圖保存的路徑一致。有任何想法嗎? – akonwi

回答

2

根據自述,paperclip-dropbox需要一個proc路徑。你的路徑中的:avatar參數是否意味着什麼,或者它是否意味着是靜態部分?

我想你需要嘗試這樣的:

:path => proc { |style| "avatars/#{id}/#{style}/#{avatar.original_filename}" } 

您也可以嘗試沒有|style|變量,但你可能會得到一個錯誤的號碼參數錯誤。通常,您可以定義其他樣式,以自動將圖片縮放到您網站上需要的尺寸 - 查看docs瞭解更多信息。

+0

非常感謝。我將它配置爲爲我所需要的工作,因爲我正在存儲文本文件而不是圖像 – akonwi