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

51 lines
1.2 KiB
Ruby
Raw Normal View History

2012-01-31 10:31:31 +00:00
class AdImage
include Mongoid::Document
include Mongoid::Timestamps
mount_uploader :file, ImageUploader
2012-04-01 15:39:49 +00:00
field :title, localize: true
field :context, localize: true
2012-04-01 15:39:49 +00:00
field :direct_to_after_click,type: Boolean
field :weight ,type: Integer ,default: 1
field :out_link #the link itself
field :link_open #how will the link be opened
LINK_OPEN_TYPES = ["new_window","local"]
2012-01-31 10:31:31 +00:00
2012-04-01 15:39:49 +00:00
field :post_date,type: Date
field :unpost_date,type: Date
belongs_to :ad_banner
before_validation :add_http
2012-08-13 03:03:11 +00:00
validates :out_link, :format => /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix, :allow_blank => true
2012-04-01 15:39:49 +00:00
def display?
if (self.post_date <= Date.today && (self.unpost_date.nil? || self.unpost_date>= Date.today) rescue false)
return true
end
return false
end
2012-01-31 10:31:31 +00:00
def get_delay_time
time = ''
if self.time_to_next.nil?
time = '1000'
else
time = (self.time_to_next.to_i * 1000).to_s
end
time
end
protected
def add_http
2012-08-13 03:03:11 +00:00
unless self.out_link[/^http:\/\//] || self.out_link[/^https:\/\//] || self.out_link.blank?
self.out_link = 'http://' + self.out_link
end
end
2012-01-31 10:31:31 +00:00
end