2016-06-29 06:57:45 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
require 'uri'
|
|
|
|
|
2022-03-10 02:11:18 +00:00
|
|
|
class ApplicationFormLink
|
2016-06-29 06:57:45 +00:00
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
|
|
|
|
|
|
|
field :url
|
|
|
|
field :title, localize: true
|
|
|
|
|
2022-03-10 02:11:18 +00:00
|
|
|
belongs_to :application_form_main
|
2016-06-29 06:57:45 +00:00
|
|
|
|
|
|
|
before_validation :add_http
|
|
|
|
|
2020-08-02 06:09:08 +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
|
2016-06-29 06:57:45 +00:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def add_http
|
|
|
|
unless self.url[/^http:\/\//] || self.url[/^https:\/\//]
|
|
|
|
self.url = 'http://' + self.url
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|