问题描述
是否可以获得回形针附件的绝对 URI?现在,问题是生产环境部署在子 URI 中(在Passenger 上:RackBaseURI
),但.url
返回Rails-应用相对 URI (/system/images/...
).有没有办法获取回形针附件的绝对 URI?
Is it possible to get the absolute URI for a Paperclip attachment? Right now, the problem is that the production environment is deployed in a sub-URI (on Passenger: RackBaseURI
), but <paperclip attachment>.url
returns the Rails-app relative URI (/system/images/...
). Is there a way to get the absolute URI for Paperclip attachments?
我使用的是 Paperclip v2.7 和 Rails 3.2.8.
I'm using Paperclip v2.7 and Rails 3.2.8.
推荐答案
try
URI.join(request.url, @model.attachment_name.url)
或
URI(request.url) + @model.attachment_name.url
使用 S3 或绝对网址是安全的.
It's safe if you use S3 or absolute url.
更新:这个答案比我的好;) https://stackoverflow.com/a/21027839/683157
Update: this answer is better than mine ;) https://stackoverflow.com/a/21027839/683157
这篇关于获取回形针附件的绝对 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!