links/app/models/web_link.rb

43 lines
1.1 KiB
Ruby

# encoding: utf-8
class WebLink
include Mongoid::Document
include Mongoid::Timestamps
include OrbitModel::Status
include OrbitModel::Impression
include OrbitTag::Taggable
include OrbitCategory::Categorizable
field :image_description, type: String, localize: true
mount_uploader :image, ImageUploader
field :title, localize: true
field :context, localize: true
field :order_position, type: Integer, default: -1
field :url, localize: true
field :create_user_id
field :update_user_id
field :rss2_id, type: String
field :link_open, type: String
LINK_OPEN_TYPES = ["local", "new_window"]
scope :can_display, ->{where(is_hidden: false).order_by([:is_top,:desc],[:order_position,:asc])}
before_save :add_http
protected
def add_http
temp_url = {}
Site.first.in_use_locales.each do |locale|
locale = locale.to_s
temp_url[locale] = self.url_translations[locale]
unless /https?:\/\/[\S]+/.match(self.url_translations[locale]) || self.url_translations[locale].blank?
temp_url[locale] = 'http://' + self.url_translations[locale]
end
end
self.url_translations = temp_url
end
end