图片的Rails 3.1绝对URL [英] Rails 3.1 absolute URL to an image

查看:63
本文介绍了图片的Rails 3.1绝对URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Rails 3.1.我正在尝试弄清楚这一点,令我惊讶的是,似乎开始完全没有Rails附带这种方法.也许我错了.

I'm using Rails 3.1. I'm trying to figure this out, and to my surprise, it is starting to seem that rails does not come with this method at all. Maybe im wrong.

谁能告诉我如何获得图像的完整绝对URL?

Can anyone show how I can get a full absolute URL to an image?

我使用asset_path(image.png),它为我提供了在应用程序中使用的相对路径.我尝试做一个root_url + asset_path(image.png),但这只是给我一个带有双斜杠的http://localhost:3000//assets/image.png

I use asset_path(image.png) which gives me the relative path to use within the app. I tried doing a root_url + asset_path(image.png) but that just gives me a http://localhost:3000//assets/image.png with the double slashes

有人有这样做的有效方法吗?

Anyone have an efficient way of doing this?

推荐答案

请参见

See the Using asset hosts section in the documentation. You need to specify an asset_host. You can also construct it dynamically from the request chaining "#{request.protocol}#{request.host_with_port}"

这篇关于图片的Rails 3.1绝对URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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