Structure link with json

This commit is contained in:
chris committed 2013-10-23 18:39:40 +08:00
1 parent a4d1c68299
commit 8ebfac2b99
13 files changed
+124 -136

No files matched your search

+16 -5
View File
@@ -1,8 +1,8 @@
class Link < Item
field :url
field :url, localize: 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
# 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
before_validation :add_http
@@ -10,12 +10,23 @@ class Link < Item
ApplicationController.helpers.link_to(self.name, self.url)
end
def urls
self.url_translations.inject({}) do |result, (key, value)|
result["url-#{key}"] = value
result
end
end
protected
def add_http
unless self.url[/^(http|https):\/\//] || self.url.blank?
self.url = 'http://' + self.url
end
if self.url_translations.present?
self.url_translations.each_value do |u|
unless u[/^(http|https):\/\//] || u.blank?
u = 'http://' + u
end
end
end
end
end