links/app/models/web_link.rb

30 lines
791 B
Ruby
Raw Normal View History

2014-05-05 11:33:35 +00:00
# encoding: utf-8
2014-05-05 08:20:37 +00:00
class WebLink
include Mongoid::Document
2014-05-05 11:33:35 +00:00
include Mongoid::Timestamps
include OrbitModel::Status
include OrbitTag::Taggable
include OrbitCategory::Categorizable
field :title, localize: true
field :context, localize: true
field :url, localize: true
field :create_user_id
field :update_user_id
scope :can_display, ->{where(is_hidden: false)}
before_validation :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
end
end
end