Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. If an error occurs throughout this run I want specific information to be logged including the Rundeck URL which the script is running on.

Is there such a way in Ruby to get the current URL?

like image 781
Michael O'Reilly Avatar asked Feb 12 '26 05:02

Michael O'Reilly


1 Answers

Depends on which type of URL you want:

For Realtive URL : request.request_uri

For Absolute URL : request.original_url

Implementation :

def original_url
  base_url + original_fullpath
end

If you are on rails 3 : request.fullpath

like image 94
kartik Avatar answered Feb 15 '26 10:02

kartik