File download using Paperclip

妖精的绣舞 提交于 2019-12-03 15:43:58

问题


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.

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?


回答1:


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.




回答2:


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,

then replace whatever by resource



来源:https://stackoverflow.com/questions/5016194/file-download-using-paperclip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!