获取回形针附件的绝对 URL [英] Get absolute URL for paperclip attachment

查看:66
本文介绍了获取回形针附件的绝对 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以获得回形针附件的绝对 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆