JoHksi JoHksi - 7 months ago 36
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.


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

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