Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get hostname from Rails controller

I am trying to get the hostname of the machine which a rails application is running on from the controller.

What would be the best way to do this taking into account it should work on both windows and linux?

like image 402
RailsSon Avatar asked Feb 05 '10 16:02

RailsSon


1 Answers

All you have to do is look at the request object in your controller:

request.host_with_port 

or if you don't want the port, just

request.host 
like image 111
Wilhelm Avatar answered Sep 20 '22 22:09

Wilhelm