Sha256: 9a036fe0757c2b397e339e54f5964d2997b11e00387a813f8f3f5882e5051197
Contents?: true
Size: 927 Bytes
Versions: 22
Compression:
Stored size: 927 Bytes
Contents
class UrlValidator < ActiveModel::EachValidator def initialize(options = {}) super(options) if options.key?(:with_schema) @with_schema = options[:with_schema] else @with_schema = true end end def validate_each(record, attribute, value) begin URI.parse(value) rescue URI::InvalidURIError record.errors.add(attribute, options[:message] || "はURLとして正しくありません。") return end if @with_schema unless value.start_with?('http://') or value.start_with?('https://') record.errors.add(attribute, options[:message] || "は http:// または https:// から始めてください。") end else if value.start_with?('http://') or value.start_with?('https://') record.errors.add(attribute, options[:message] || "は http:// または https:// を含めないでください。") end end end end
Version data entries
22 entries across 22 versions & 1 rubygems