Paperclip Force下载

希望任何人都可以提供帮助!

利用Paperclip将文件上传到应用程序,这是我需要涵盖的两件事。

1)链接到File for Download的最佳方式是什么,我目前正在链接到公共文件夹,但它不是最好的选项,因为它显示了我不想要的URL。 想想也许一个button_to调用不确定它是否已经构建到Paperclip中。 选项。

2)当完成上述操作后,浏览器需要强制下载而不仅仅是打开文件,或者至少给用户打开或保存标准的firefox选项。

请帮助米勒!

我会回答Nº2的问题。
假设你的模型叫做gallery。
在您的图库控制器中,您将添加下载方法:

def download @gallery= Gallery.find(params[:gallery_id]) send_file @gallery.gallery_picture.path, :filename => @gallery.gallery_picture_file_name, :type => @gallery.gallery_picture_content_type, :disposition => 'attachment' end 

现在从你的路线你将调用根到这个方法:

 match 'gallery/:id' => 'gallery#download', :as => :download 

在您的观点中:

 - @galleries.each do |gallery| = link_to 'Download Picture', download_path(gallery.id) 

我不在家,我无法测试此代码,但您可以访问我用与您相同的问题做的那些问题。 如果它能解决您的问题,请告诉我。

Rails send_file来自Paperclip的多个样式,如何避免代码重复?
Rails 3.0关联模型,下载’保存到’图像

在rails中,带有用户参数设置的send_file是一个安全漏洞。 更多信息

在rails 4中你不能只写match ,你必须在最后添加, via: [:get, :post] 。 更多信息