Skip to content

Instantly share code, notes, and snippets.

@adammcarth
Last active December 25, 2015 03:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adammcarth/6913977 to your computer and use it in GitHub Desktop.
Save adammcarth/6913977 to your computer and use it in GitHub Desktop.
Validate website url
class Comment < ActiveModel::Base
validate :valid_url?, :allow_blank => true
def valid_url?
if (self.website).start_with?("http://", "https://") and (self.website).end_with?(".*")
return true
elsif (self.website).end_with?(".*")
return true
self.website = "http://#{self.website}"
else
return self.errors[:website] << "The website you entered (#{self.website}) is invalid. Please try again."
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment