我在使用 paperclip-dropbox gem 时遇到了一些问题。
我有一个简单的用户模型,包含名称、密码等和图像。我正在尝试将该图像上传到保管箱,但它不起作用。
该文件保存在我的 /system/users/images/000/000/ 文件夹中。 image_file_name、image_content_type、image_file_size 和 image_updated_at 数据与用户名一起正确保存在我的数据库中、密码等
我使用的是ruby 2.2.1p85和Rails 4.2.0。我的 Gemfile 中有回形针-dropbox gem,并且已正确安装。我已在 Dropbox 中创建了该应用程序,但在应用程序文件夹中没有上传任何内容。
回形针-dropbox gem 似乎没有完成其工作,因为我可以在 config/dropbox.yml 中放入我想要的任何内容(例如,错误的 app_key 和/或 access_token 值),但它没有不要抛出任何身份验证错误或任何错误。
这里有一些代码,以便您可以看到我在做什么,并可能指出哪里出了问题:
用户模型:
class User < ActiveRecord::Base
has_attached_file :image
validates_attachment_content_type :image, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"],
:storage => :dropbox,
:dropbox_credentials => Rails.root.join("config/dropbox.yml"),
:dropbox_options => {:path => proc { |style| "files/#{id}/#{file.original_filename}" } }
end
在用户 Controller 上创建方法:
def create
@user = User.new(user_params)
respond_to do |format|
if @user.save
format.html { redirect_to @user, notice: 'User was successfully created.' }
format.json { render :show, status: :created, location: @user }
else
format.html { render :new }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
我已设置好config/dropbox.yml。
有什么建议吗?预先非常感谢!
最佳答案
您的保管箱选项应位于 has_attached_file
方法中:
has_attached_file :image,
:storage => :dropbox,
:dropbox_credentials => Rails.root.join("config/dropbox.yml"),
:dropbox_options => {:path => proc { |style| "files/#{id}/#{file.original_filename}" } }
validates_attachment_content_type :image, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"]
关于ruby-on-rails - Rails paperclip-dropbox 未上传到 Dropbox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31518666/