Check for 'http' or 'https' before saving a link
This commit is contained in:
1 parent
5fc679e0ca
commit
5f88408dcb
4 files changed
+45
No files matched your search
@@ -26,6 +26,9 @@ class WebLink
|
||||
|
||||
validates :title, :at_least_one => true
|
||||
|
||||
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
|
||||
|
||||
def self.search( category_id = nil )
|
||||
|
||||
if category_id.to_s.size > 0
|
||||
@@ -64,5 +67,13 @@ class WebLink
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def add_http
|
||||
unless self.url[/^http:\/\//] || self.url[/^https:\/\//]
|
||||
self.url = 'http://' + self.url
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
Reference in new issue
Block a user