Ruby on Rails如何获取当前URL? [英] Ruby on Rails how to get current URL?

查看:489
本文介绍了Ruby on Rails如何获取当前URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 request.host request.url 获取当前网址,但我有一个网站位于2个网域,因此:

I'm trying to get the current url in rails using request.host, request.url but I have a website that are in 2 domains, so:

当我在 www.example1.com request.host 或.url显示 www.example1.com

when I'm at www.example1.com the request.host or .url show www.example1.com

当我在 www.example2.com request.host 或.url show example1.com
,因为example2正在从example1获取所有内容,并在example2(已解析)

when I'm at www.example2.com the request.host or .url show example1.com because the example2 is getting all content from example1 and showing in the example2(parsed)

中显示request.host得到真正的主机,并且request.url获取主机也
我真的需要获取url在浏览器中不是主机,有人可以帮助吗?

because the request.host get really the host, and request.url getting the host also I'm really need the get the url in the browser don't the host, someone can help?

OB:我使用rails 4和ruby 2
OBs2:request.domain不起作用,只返回.com的url

OBs: I'm using rails 4 and ruby 2 OBs2: request.domain don't works, this return just ".com" of url

推荐答案

request.original_url 

将在rails 4中提供您当前的网址。

shall provide you current url in rails 4.

您可以访问此资源获取更多信息@ 如何在Ruby on Rails中获取当前的绝对URL?

You can visit this resource for more info @ How do I get the current absolute URL in Ruby on Rails?

这篇关于Ruby on Rails如何获取当前URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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