Rails 公共目录的绝对 URL
我需要调用什么方法来查找 Rails 应用程序的根 URL。例如,我有一个地址为“https://host:1234/foo/app-main”的网站。
我应该使用什么方法来获取“https://host:1234/foo/images”来获取公共网址中图像的绝对网址?
What is the method I need to call to find the root URL for a rails application. For example, I have a site where the address is "https://host:1234/foo/app-main".
What method should I be using to get "https://host:1234/foo/images" to get the absolute url for images in the public url?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
image_path(image_name)
编辑:史蒂夫有一个好点,这只会让你到达那里的一部分。要获得其余部分,您必须处于请求范围内(您可能是),
但在这种情况下,您可以将上述内容与 Justice 的方法结合起来,
image_path(image_name)
Edit: Steve has a good point, this will only get you part of the way there. To get the rest you must be inside of a request (you probably are)
In that case though, you can combine the above with Justice's approach,
这个问题仅在每个请求的基础上才有意义,因为您的一个进程可能很容易监听多个域名和多个方案。
请参阅
Rack::Request
。This question makes sense only on a per-request basis, since your one process might easily be listening on multiple domain names and on multiple schemes.
See
Rack::Request
.