简体   繁体   English

如何在Ruby中获取当前网址?

[英]How to get current url in Ruby?

I am trying to create a Chef recipe for error handling, this recipe will be ran through Rundeck. 我正在尝试创建一个用于处理错误的Chef食谱,该食谱将通过Rundeck运行。 If an error occurs throughout this run I want specific information to be logged including the Rundeck URL which the script is running on. 如果在整个运行过程中发生错误,我希望记录特定信息,包括运行脚本的Rundeck URL。

Is there such a way in Ruby to get the current URL? Ruby中是否有这种方法来获取当前URL?

Depends on which type of URL you want: 取决于所需的URL类型:

For Realtive URL : request.request_uri 对于真实网址: request.request_uri

For Absolute URL : request.original_url 对于绝对URL: request.original_url

Implementation : 实现方式:

def original_url
  base_url + original_fullpath
end

If you are on rails 3 : request.fullpath 如果您在轨道3上: request.fullpath

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM