Get server file path with Paperclip

谁都会走 提交于 2019-11-30 13:11:39

问题


I'm using Rails with Paperclip to make a small file upload app. I would like to be able to return the file path on the server of the uploaded file once its done but I can't seem to work out how to get the path? Paperclip only seems to record the name of the file itself.

Does anybody now how to do this?


回答1:


Assuming you had an attachment called avatar on an instance of a user, you can use user.avatar.path to get the full path of the file on the filesystem, and you can use user.avatar.url to give the path which you could use in image tags and whatnot.

Is that what you're meaning?




回答2:


I came cross the same problem, so I made a link to it's url in show.html.erb. It works.

<p>
<b>Pdf:</b><%= link_to "PDF" , @product.pdf.url %>
</p>


来源:https://stackoverflow.com/questions/4984604/get-server-file-path-with-paperclip

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