links/app/models/web_link.rb

37 lines
944 B
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 :title, localize: true
field :context, localize: true
field :url, localize: true
field :create_user_id
field :update_user_id
field :rss2_id, type: String
scope :can_display, ->{where(is_hidden: false).order_by([:is_top,:desc],[:created_at,:desc])}
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