无法弄清楚如何做到这一点?并且在其他任何地方都找不到太多帮助!
我已经像这样设置了回形针和雾;
配置/初始化程序/fog.rb
connection = Fog::Storage.new({
:provider => 'Rackspace',
:rackspace_username => '',
:rackspace_api_key => ''
})
环境.rb;
Paperclip::Attachment.default_options.update({
:path => ":attachment/:id/:timestamp_:style.:extension",
:storage => :fog,
:fog_credentials => {
:provider => 'Rackspace',
:rackspace_username => '',
:rackspace_api_key => '',
:persistent => false
},
:fog_directory => '',
:fog_public => true
})
我file_field
用来获取图像,然后将其发布到我的控制器。这让我得到了这样的东西;
"pic"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x007f90ac06a6c8 @original_filename="3245-1920x1200.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"cloth[pic][image]\"; filename=\"3245-1920x1200.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<File:/tmp/RackMultipart20130104-5386-103laem>>}
我无法理解的是,我该如何使用类似的方法将此文件实际保存到云文件中;
file = directory.files.create(
:key => 'resume.html',
:body => File.open("/path/to/my/resume.html"),
:public => true
)
编辑
相关模型;
class Cloth
include Mongoid::Document
has_many :pics
class Pic
include Mongoid::Document
include Mongoid::Paperclip
belongs_to :cloth
has_mongoid_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100>" }
在控制器中,这就是我当前基于上述参数创建图片的方式;
@cloth = Cloth.new
@cloth.pics.create!(params[:cloth][:pic])