Strip trailing slashes from ScreeningUrl records

This commit is contained in:
Neil Lalonde
2013-09-17 10:25:45 -04:00
parent 6183e9bb6c
commit b15e629f46
2 changed files with 14 additions and 3 deletions

View File

@ -11,13 +11,16 @@ class ScreenedUrl < ActiveRecord::Base
default_action :do_nothing
before_validation :strip_http
before_validation :normalize
validates :url, presence: true, uniqueness: true
validates :domain, presence: true
def strip_http
self.url.gsub!(/http(s?):\/\//i, '')
def normalize
if self.url
self.url.gsub!(/http(s?):\/\//i, '')
self.url.gsub!(/(\/)+$/, '') # trim trailing slashes
end
end
def self.watch(url, domain, opts={})