This commit is contained in:
BoHung Chiu 2022-11-18 22:24:15 +08:00
parent fb56f5bd86
commit f174bf290f
1 changed files with 4 additions and 3 deletions

View File

@ -10,15 +10,16 @@ class BulletinLink
belongs_to :bulletin belongs_to :bulletin
before_validation :add_http before_save :add_http
#validates :url, :presence => true, :format => /\A(http|https):\/\/(([a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5})|((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(:[0-9]{1,5})?(\/.*)?\Z/i #validates :url, :presence => true, :format => /\A(http|https):\/\/(([a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5})|((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(:[0-9]{1,5})?(\/.*)?\Z/i
protected protected
def add_http def add_http
unless self.url[/^http:\/\//] || self.url[/^https:\/\//] tmp = self.url
self.url = 'http://' + self.url unless tmp.match(/^http(s|):\/\//) || tmp.blank? || tmp.start_with?('/')
self.url = 'http://' + tmp
end end
end end