orbit-announcement/app/models/bulletin_link.rb

26 lines
616 B
Ruby
Raw Normal View History

2014-01-14 11:54:35 +00:00
class BulletinLink
include Mongoid::Document
include Mongoid::Timestamps
field :url
field :title, localize: true
field :should_destroy, :type => Boolean
# embedded_in :bulletin
belongs_to :bulletin
before_validation :add_http
validates :url, :presence => true, :format => /^(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})?(\/.*)?/i
protected
def add_http
unless self.url[/^http:\/\//] || self.url[/^https:\/\//]
self.url = 'http://' + self.url
end
end
end