From 8f85d8939fe1297b4b536d60b937185fb1ac1ffb Mon Sep 17 00:00:00 2001 From: manson Date: Fri, 6 Jun 2014 19:06:02 +0800 Subject: [PATCH] Fix status and add_http method --- app/models/web_link.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/models/web_link.rb b/app/models/web_link.rb index 07f6361..54db767 100644 --- a/app/models/web_link.rb +++ b/app/models/web_link.rb @@ -15,17 +15,22 @@ class WebLink field :create_user_id field :update_user_id - scope :can_display, ->{where(is_hidden: false)} + scope :can_display, ->{where(is_hidden: false).order_by([:is_top, :desc])} - 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 + before_save :add_http protected def add_http - unless self.url[/^http:\/\//] || self.url[/^https:\/\//] - self.url = 'http://' + self.url + 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 \ No newline at end of file