我正在尝试使用paperclip-dropbox gem here,我遇到了设置问题并传递了我的凭据。
在文档中,模型中的设置完成如下:
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'
然后rails说“错误的参数类型String expected Proc”
我是ruby的新手并且不太了解触发器。我如何解决这个问题才能让它发挥作用?
答案 0 :(得分:2)
根据自述文件,paperclip-dropbox需要路径的proc。路径中的:avatar
参数是否意味着什么,或者是否意味着是静态部分?
我认为你需要尝试这样的事情:
:path => proc { |style| "avatars/#{id}/#{style}/#{avatar.original_filename}" }
你也可以在没有|style|
变量的情况下尝试它,但是你可能会得到错误数量的参数错误。通常情况下,可以定义其他样式以自动将图像缩放到您网站上所需的尺寸 - 有关详细信息,请查看docs。