Fix link in structure

This commit is contained in:
chris committed 2013-10-30 18:53:23 +08:00
1 parent a885313e75
commit 00010867a4
5 files changed
+32 -26

No files matched your search

+16 -7
View File
@@ -1,6 +1,8 @@
class Link < Item
field :url, localize: true
validates :url, at_least_one: true
# validates :url, :presence => true, :format => /^(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]?))|localhost(:[0-9]{1,5})?(\/.*)?/i
@@ -11,20 +13,27 @@ class Link < Item
end
def urls
self.url_translations.inject({}) do |result, (key, value)|
result["url-#{key}"] = value
result
end
if self.url_translations.present?
self.url_translations.inject({}) do |result, (key, value)|
result["url-#{key}"] = value
result
end
else
{}
end
end
protected
def add_http
if self.url_translations.present?
self.url_translations.each_value do |u|
unless u[/^(http|https):\/\//] || u.blank?
u = 'http://' + u
self.url_translations = self.url_translations.inject({}) do |translations, (key, value)|
if value.blank? || value[/^(http|https):\/\//]
translations[key] = value
else
translations[key] = 'http://' + value
end
translations
end
end
end