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 AdImage
|
||||
# validates_format_of :out_link, with: /(http:\/\/.*|)/ ,:message => 'Need a valid URL'
|
||||
attr_reader :parse_post_date,:parse_unpost_date
|
||||
|
||||
before_validation :add_http
|
||||
validates :out_link, :presence => true, :format => /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix
|
||||
|
||||
def parse_post_date=(att)
|
||||
self.post_date = (Date.parse att.gsub(/\s+/, "") rescue nil)
|
||||
end
|
||||
@@ -52,4 +55,12 @@ class AdImage
|
||||
end
|
||||
time
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def add_http
|
||||
unless self.out_link[/^http:\/\//] || self.out_link[/^https:\/\//]
|
||||
self.out_link = 'http://' + self.out_link
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user