Fix status and add_http method

This commit is contained in:
manson 2014-06-06 19:06:02 +08:00
parent 176d338ed2
commit 8f85d8939f
1 changed files with 10 additions and 5 deletions

View File

@ -15,17 +15,22 @@ class WebLink
field :create_user_id field :create_user_id
field :update_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 before_save :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
protected protected
def add_http def add_http
unless self.url[/^http:\/\//] || self.url[/^https:\/\//] temp_url = {}
self.url = 'http://' + self.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 end
self.url_translations = temp_url
end end
end end