Hostname

Hi,

I have written an rake task where I need to access “Hostname” . I need this feature because I will be testing my application using the rake task both locally and on live server .

I found code in another language which does the same

hostname = os.environ.get('HOSTNAME')

puts "hostname =" + hostname

Is there anything similar to the above code in rails which I can use in my application .

Thanks, Madhu Nallamani

Hi,

If you're using unix, you could do:

hostname = `hostname` puts "hostname = #{hostname}"

The backquotes simply execute the text inside them at a unix shell.

Julian.

Learn Ruby on Rails! Check out the FREE VIDS (for a limited time)
VIDEO #4 parts a and b now available! http://sensei.zenunit.com/

try:

Socket.gethostname

You may need to require the socket library first.

Jamey

Thanks Jamey and Julian .