Check for 'http' or 'https' before saving a link

This commit is contained in:
Christophe Vilayphiou committed 2012-08-04 16:29:31 +08:00
1 parent 5fc679e0ca
commit 5f88408dcb
4 files changed
+45

No files matched your search

@@ -9,4 +9,15 @@ class NewsBulletinLink
field :should_destroy, :type => Boolean
belongs_to :news_bulletin
before_validation :add_http
validates :url, :presence => true, :format => /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix
protected
def add_http
unless self.url[/^http:\/\//] || self.url[/^https:\/\//]
self.url = 'http://' + self.url
end
end
end