JoHksi JoHksi - 1 year ago 130
Ruby Question

Get hostname of URL in ruby on rails

I am making rails app and I need to get just hostname of my URL from my one of Rails controllers.

If my URL is
,then I just want to extract
part. How can I do this? I found
but this returns
which I do not want.

In javascript there is a function,
. I wonder there is a equivalent in Ruby on Rails.

Answer Source

You can use to get exact your URL which you want.

And you can use request.port to get your port from url

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download