Class: ActiveRecord::Validations::WebsiteValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/validates_as_website.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



5
6
7
8
9
10
# File 'lib/validates_as_website.rb', line 5

def validate_each(record, attribute, value)
  return if not (value.is_a?(String) ? value : value.to_s).match(/\A(http|https)[:]\/{2}[^\/.]+([.][^\/.]+)+.*\Z/i).nil?
  record.errors.add(attribute, 
                    I18n.translate('activerecord.errors.messages.invalid', :default => 'invalid'), 
                    options.merge(:value => value))
end