Sha256: aabad6300e5398fb3d68cccb061396c6cfe9cf19f7655c8a17b0d536a0f8b601

Contents?: true

Size: 379 Bytes

Versions: 7

Compression:

Stored size: 379 Bytes

Contents

# frozen_string_literal: true

module EacRailsUtils
  # https://stackoverflow.com/questions/10070786/rails-3-validation-presence-false
  class NoPresenceValidator < ActiveModel::EachValidator
    def validate_each(record, attribute, _value)
      return if record.send(attribute).blank?

      record.errors.add(attribute, options[:message] || 'must be blank')
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
eac_rails_utils-0.25.0 app/validators/eac_rails_utils/no_presence_validator.rb
eac_rails_utils-0.24.0 app/validators/eac_rails_utils/no_presence_validator.rb
eac_rails_utils-0.23.4 app/validators/eac_rails_utils/no_presence_validator.rb
eac_rails_utils-0.23.3 app/validators/eac_rails_utils/no_presence_validator.rb
eac_rails_utils-0.23.2 app/validators/eac_rails_utils/no_presence_validator.rb
eac_rails_utils-0.23.1 app/validators/eac_rails_utils/no_presence_validator.rb
eac_rails_utils-0.23.0 app/validators/eac_rails_utils/no_presence_validator.rb