Get server file path with Paperclip

2019-02-03 23:57发布

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?

2条回答
劳资没心,怎么记你
2楼-- · 2019-02-04 00:49

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?

查看更多
神经病院院长
3楼-- · 2019-02-04 01:04

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>
查看更多
登录 后发表回答