Module: ActiveModel::Validations::ClassMethods

Defined in:
lib/validate_url.rb

Instance Method Summary collapse

Instance Method Details

#validates_url(*attr_names) ⇒ Object

Validates whether the value of the specified attribute is valid url.

class Unicorn
  include ActiveModel::Validations
  attr_accessor :homepage, :ftpsite
  validates_url :homepage, allow_blank: true
  validates_url :ftpsite, schemes: ['ftp']
end

Configuration options:

  • :message - A custom error message (default is: “is not a valid URL”).

  • :allow_nil - If set to true, skips this validation if the attribute is nil (default is false).

  • :allow_blank - If set to true, skips this validation if the attribute is blank (default is false).

  • :schemes - Array of URI schemes to validate against. (default is [‘http’, ‘https’])



85
86
87
# File 'lib/validate_url.rb', line 85

def validates_url(*attr_names)
  validates_with UrlValidator, _merge_attributes(attr_names)
end