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.
orbit-4-1/app/models/link.rb

22 lines
515 B
Ruby
Raw Normal View History

class Link < Item
field :url
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]?))(:[0-9]{1,5})?(\/.*)?/i
before_validation :add_http
def link
ApplicationController.helpers.link_to(self.name, self.url)
end
protected
def add_http
unless self.url[/^http:\/\//] || self.url[/^https:\/\//]
self.url = 'http://' + self.url
end
end
end