[英]File download using Paperclip
I am using Rails to make a small file upload app. 我正在使用Rails制作一个小文件上传应用程序。 For file attachment I am using the wonderful Paperclip but I can't work out how to do downloads.
对于文件附件我使用精彩的Paperclip,但我无法弄清楚如何进行下载。
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? 如何在我的节目视图中创建一个链接,即传递文件ID,例如允许用户在我的服务器上下载文件?
If the file uploaded is attached to a model, eg as an attribute called avatar
, then you can create a link like: 如果上传的文件附加到模型,例如作为名为
avatar
的属性,则可以创建如下链接:
<%= link_to "Download", model.avatar.url(:original, false) %>
Replace avatar
with the name of your attribute. 将
avatar
替换为您的属性名称。
Replace whatever by name that are user in your model for paper clip if you have 如果有,请替换模型中用户名称的任何内容
resource_file_name, resource_file_name, resource_file_name, resource_file_name,resource_file_name,resource_file_name,
then replace whatever by resource 然后用资源替换任何东西
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.