From f174bf290f186a2443b5e6f5c6c90ba0f07e599a Mon Sep 17 00:00:00 2001 From: bohung Date: Fri, 18 Nov 2022 22:24:15 +0800 Subject: [PATCH] Fix bug. --- app/models/bulletin_link.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/models/bulletin_link.rb b/app/models/bulletin_link.rb index a3f2b1c..678d2bd 100644 --- a/app/models/bulletin_link.rb +++ b/app/models/bulletin_link.rb @@ -10,15 +10,16 @@ class BulletinLink 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 protected def add_http - unless self.url[/^http:\/\//] || self.url[/^https:\/\//] - self.url = 'http://' + self.url + tmp = self.url + unless tmp.match(/^http(s|):\/\//) || tmp.blank? || tmp.start_with?('/') + self.url = 'http://' + tmp end end