Add http to URL it it is not present there

Using this way you can solve your problem, If there is no http or https in the url.

def add_url_protocol(url)
  !(url[/\Ahttp:\/\//] || url[/\Ahttps:\/\//]) ? "http://#{url}" : url
end

No comments:

Post a Comment