I want to check user submitted urls against a regular expression, if the url doesn’t begin with http:// or https://, then I would like to prepend http:// to the beginning then save it.
I have some code but I don’t know how to incorporate it into my app. Would this code work? And would I incorporate it into my application to check urls before allowing users to create links.
I’ve attached the code and files below. Thanks
def add_http(link)
if (link =~ /http[s]?:\/\//)
link
else
"http://#{link}"
end
end
Controller https://gist.github.com/1279576
Fixed the code a bit. This works
Thanks for the guidance @bandito & @rubyprince