This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
orbit-4-1/app/models/ad_image.rb

31 lines
965 B
Ruby
Raw Normal View History

2012-01-31 10:31:31 +00:00
class AdImage
include Mongoid::Document
include Mongoid::Timestamps
2013-10-18 07:25:19 +00:00
include OrbitModel::TimeFrame
include OrbitTag::Taggable
2012-01-31 10:31:31 +00:00
mount_uploader :file, ImageUploader
2012-04-01 15:39:49 +00:00
field :title, localize: true
2013-10-18 07:25:19 +00:00
field :context, localize: true
field :weight, type: Integer, default: 1
2012-04-01 15:39:49 +00:00
field :out_link #the link itself
field :link_open #how will the link be opened
2013-10-18 07:25:19 +00:00
LINK_OPEN_TYPES = ["local", "new_window"]
2012-04-01 15:39:49 +00:00
belongs_to :ad_banner
before_validation :add_http
2013-10-18 07:25:19 +00:00
validates :file, :presence => true
validates :out_link, :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, :allow_blank => true
2013-10-18 07:25:19 +00:00
validates :title, :at_least_one => true
protected
def add_http
2013-10-18 07:25:19 +00:00
unless self.out_link.blank? || self.out_link[/^http:\/\//] || self.out_link[/^https:\/\//]
self.out_link = 'http://' + self.out_link
end
end
2012-01-31 10:31:31 +00:00
end