2014-06-23 08:36:04 +00:00
|
|
|
# encoding: utf-8
|
2014-05-01 08:41:00 +00:00
|
|
|
require 'uri'
|
|
|
|
|
|
|
|
class BulletinLink
|
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
|
|
|
|
|
|
|
field :url
|
|
|
|
field :title, localize: true
|
|
|
|
|
|
|
|
belongs_to :bulletin
|
|
|
|
|
2022-11-18 14:24:15 +00:00
|
|
|
before_save :add_http
|
2014-05-01 08:41:00 +00:00
|
|
|
|
2020-08-02 06:11:14 +00:00
|
|
|
#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
|
2014-05-01 08:41:00 +00:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def add_http
|
2022-11-18 14:24:15 +00:00
|
|
|
tmp = self.url
|
|
|
|
unless tmp.match(/^http(s|):\/\//) || tmp.blank? || tmp.start_with?('/')
|
2022-11-19 02:58:21 +00:00
|
|
|
self.url = 'https://' + tmp
|
2014-05-01 08:41:00 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|