Get hostname from Rails controller

前端 未结 4 483
一整个雨季
一整个雨季 2021-01-01 08:23

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

4条回答
  •  耶瑟儿~
    2021-01-01 09:27

    Use backticks and the command hostname

    current_host = `hostname`
    

    This sends the command to the shell, and returns the hostname. Works on at least: Debian Linux, Windows, Solaris.

提交回复
热议问题