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

查看:26
本文介绍了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.

谁能告诉我如何获得图片的完整绝对网址?

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?

推荐答案

请参阅 文档.您需要指定一个 asset_host.您还可以从请求链 "#{request.protocol}#{request.host_with_port}"

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天全站免登陆