如何在Ruby on Rails视图中获得当前的绝对URL ?
请求。request_uri只返回相对URL。
如何在Ruby on Rails视图中获得当前的绝对URL ?
请求。request_uri只返回相对URL。
当前回答
我认为Ruby on Rails 3.0的方法现在是request.fullpath。
其他回答
request.env["REQUEST_URI"]
工作在rails 2.3.4测试,不知道其他版本。
看起来在Ruby on Rails 3中request_uri已弃用。
Using #request_uri is deprecated. Use fullpath instead.
对于Ruby on Rails 3:
request.url
request.host_with_port
我启动了一个调试器会话并查询了请求对象:
request.public_methods
在Ruby on Rails 3.1.0.rc4中:
request.fullpath
如果您所说的相对是指没有域,那么请查看request.domain。