使用Paperclip进行文件下载 [英] File download using Paperclip

查看:145
本文介绍了使用Paperclip进行文件下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Rails制作一个小型的文件上传应用程序。对于文件附件我正在使用精美的纸夹,但是我无法解决如何下载。

I am using Rails to make a small file upload app. For file attachment I am using the wonderful Paperclip but I can't work out how to do downloads.

如何在我的显示视图中创建一个链接,传递文件ID,例如允许用户在我的服务器上下载文件? p>

How would I create a link in my show view, that is passed the file id, for instance that would allow the user to download a file on my server?

推荐答案

如果上传的文件附加到模型,例如作为一个名为头像的属性,您可以创建一个链接,如:

If the file uploaded is attached to a model, e.g. as an attribute called avatar, then you can create a link like:

<%= link_to "Download", model.avatar.url(:original, false) %>

用您的属性名称替换头像

Replace avatar with the name of your attribute.

这篇关于使用Paperclip进行文件下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆