orbit-basic/vendor/built_in_modules/announcement/app/models/bulletin_link.rb

26 lines
529 B
Ruby
Raw Normal View History

2012-02-06 07:23:27 +00:00
class BulletinLink
include Mongoid::Document
include Mongoid::Timestamps
field :url
2012-07-25 18:27:43 +00:00
field :title, localize: true
2012-02-06 07:23:27 +00:00
field :should_destroy, :type => Boolean
2012-03-14 12:05:03 +00:00
# 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}(([0-9]{1,5})?\/.*)?$/ix
protected
def add_http
unless self.url[/^http:\/\//] || self.url[/^https:\/\//]
self.url = 'http://' + self.url
end
end
2012-02-06 07:23:27 +00:00
end