Skip to content

Instantly share code, notes, and snippets.

@kvirani
Created March 26, 2012 15:40
Show Gist options
  • Save kvirani/2206046 to your computer and use it in GitHub Desktop.
Save kvirani/2206046 to your computer and use it in GitHub Desktop.
def url_valid
url = URI.parse(get_linkedin_profile)
unless %w( http https ).include?(url.scheme) && (url.hostname.include? "linkedin") && !url.path.blank?
errors.add(:detail, "Please Enter a Valid Linkedin Profile URL")
end
rescue URI::InvalidURIError => e
errors.add(:detail, "Please Enter a Valid Linkedin Profile URL")
end
#This method works fine but How can I better handle invalid string values like linkedin_url = ">>>>>" ?
# Now such string gives me this error instead of error message
URI::InvalidURIError in UsersController#action
bad URI(is not URI?): >>>>>>>>>>>>>>>>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment