Sha256: 44eb56311a2fc25f6736c50066180909352ec681707ee78e1fa680fcbd533322
Contents?: true
Size: 605 Bytes
Versions: 2
Compression:
Stored size: 605 Bytes
Contents
#!/usr/bin/env ruby require "active_model" require "active_support/core_ext" # Checks a value not equals to another attribute's one. # # validates :password, not_equals_to: :login # # Use the <tt>:allow_nil</tt> key to skip validation in case the attribute value isn't set. # # validates :password, not_equals_to: :login, allow_nil: true # class NotEqualsValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) return if value.nil? && options[:allow_nil] if value == record.send(options[:to]) record.errors.add attribute, :not_equals end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
active_validators-1.1.1 | lib/validators/not_equals_validator.rb |
active_validators-1.1.0 | app/validators/not_equals_validator.rb |