希望任何人都可以在这方面提供帮助!
利用 Paperclip 将文件上传到应用程序,所以我需要介绍两件事。
1) 链接到下载文件的最佳方式是什么,我目前正在链接到公用文件夹,但这不是最佳选择,因为它显示了我不想要的 URL。想也许一个 button_to 调用不确定这是否已经内置到 Paperclip 中。选项。
2)完成上述操作后,浏览器需要强制下载,而不仅仅是打开文件,或者至少为用户提供标准的 firefox 选项打开或保存。
请协助谢谢米尔!!!
最佳答案
我将回答问题 Nº2。
假设您的模型称为画廊。
在您的画廊 Controller 中,您将添加一个下载方法:
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
现在从您的 route ,您将调用此方法的根:
match 'gallery/:id' => 'gallery#download', :as => :download
在您看来:
- @galleries.each do |gallery|
= link_to 'Download Picture', download_path(gallery.id)
我不在家,无法测试此代码,但您可以访问我使用与您相同的问题所做的那些问题。让我知道它是否能解决您的问题。
Rails send_file multiple styles from Paperclip, how can I avoid code repetition?
Rails 3.0 associated model with download 'save to' image
关于ruby-on-rails - 回形针力 下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14406082/