property_hire/app/models/property_link.rb

25 lines
479 B
Ruby

# encoding: utf-8
require 'uri'
class PropertyLink
include Mongoid::Document
include Mongoid::Timestamps
field :url, :type => String, :default=> ""
field :title, :type => String, :default=> ""
before_validation :add_http
belongs_to :property
def display_title
self.title.blank? ? self.url : self.title
end
protected
def add_http
unless self.url[/^http:\/\//] || self.url[/^https:\/\//]
self.url = 'http://' + self.url
end
end
end