我有一些问题与回形针-dropbox创业板。
我有一个简单的用户模型,名称,密码等和图像。我想把这张照片上传到dropbox,但不管用。
该文件保存在我的/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。我有回形针-dropbox宝石在我的Gemfile和正确安装。我在Dropbox中创建了这个应用程序,但是在“应用程序”文件夹中,没有任何东西被上传。
看起来这个回形针-dropbox.yml没有做好它的工作,因为我可以将我想要的任何东西放入我的config/disbox.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用户控制器上的创建方法:
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都准备好了。
有什么建议吗?提前谢谢!
发布于 2015-07-20 14:23:02
您的dropbox选项应该位于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"]https://stackoverflow.com/questions/31518666
复制相似问题