Method: ActiveModel::Validations::ClassMethods#validates_url
- Defined in:
- lib/url_validator.rb
#validates_url(*attr_names) ⇒ Object
Validates whether the value of the specified attribute is valid url.
class User
include ActiveModel::Validations
attr_accessor :website, :ftpsite
validates_url :website, :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 isnil(default isfalse). -
:allow_blank- If set to true, skips this validation if the attribute is blank (default isfalse). -
:schemes- Array of URI schemes to validate against. (default is [‘http’, ‘https’])
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/url_validator.rb', line 48 def validates_url(*attr_names) attrs = attr_names.take_while{|a| !a.instance_of?(Hash)} attrs.each do |a_name| class_eval " def \#{a_name}_normalized\n Addressable::IDNA.to_ascii(\#{a_name}.to_s)\n end\n EOF\n end\n validates_with UrlValidator, _merge_attributes(attr_names)\nend\n" |