module ActionDispatch::Http::URL

def host

req.host # => "example.com"
req = ActionDispatch::Request.new 'HTTP_HOST' => 'example.com:8080'

Returns the host for this request, such as "example.com".
def host
  raw_host_with_port.sub(/:\d+$/, "")
end