ruby-on-rails - Rails paperclip-dropbox 未上传到 Dropbox

标签 ruby-on-rails ruby paperclip dropbox

我在使用 paperclip-dropbox gem 时遇到了一些问题。

我有一个简单的用户模型,包含名称、密码等和图像。我正在尝试将该图像上传到保管箱,但它不起作用。

该文件保存在我的 /system/users/images/000/000/ 文件夹中。 image_file_nameimage_content_typeimage_file_sizeimage_updated_at 数据与用户名一起正确保存在我的数据库中、密码等

我使用的是ruby 2.2.1p85Rails 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/

相关文章:

ruby-on-rails - Rails3 应用程序的起点,它将成为 iphone 应用程序的后端

ruby-on-rails - Rails 模型中的条件回调?

ruby-on-rails - HashWithIndifferentAccess 不适用于 Rails 5 中的 % 格式运算符

ruby - 如何在 ubuntu 14.04 上运行的 ruby​​ 中以编程方式解压缩 .tar.xz 文件(没有中间体)?

ruby-on-rails - Rails 4 + Postgresql - 加入具有 2 个条件的表

ruby - 检查字符串是否包含一个或多个单词

ruby-on-rails - 尝试在 RoR 应用程序中发送电子邮件时遇到 SMTP 错误

ruby-on-rails - Rails回形针和SVG图像

ruby-on-rails - 如何在将回形针附件上传到 S3 之前对其进行加密?

ruby-on-rails - 使用回形针上传大文件时JVM报错