This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
2010-01-14 10:30:53 +00:00
|
|
|
class Link < Item
|
|
|
|
|
2011-04-13 10:19:51 +00:00
|
|
|
field :url
|
2010-01-14 10:30:53 +00:00
|
|
|
|
2012-05-14 13:43:10 +00:00
|
|
|
validates :url, :presence => true, :format => /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix
|
|
|
|
|
|
|
|
before_validation :add_http
|
2011-04-13 10:19:51 +00:00
|
|
|
|
2010-01-14 10:30:53 +00:00
|
|
|
def link
|
2011-04-13 10:19:51 +00:00
|
|
|
ApplicationController.helpers.link_to(self.name, self.url)
|
2010-01-14 10:30:53 +00:00
|
|
|
end
|
2012-05-14 13:43:10 +00:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def add_http
|
|
|
|
unless self.url[/^http?s:\/\//]
|
|
|
|
self.url = 'http://' + self.url
|
|
|
|
end
|
|
|
|
end
|
2010-01-14 10:30:53 +00:00
|
|
|
|
2011-04-13 10:19:51 +00:00
|
|
|
end
|