lines_validator.rb 311 B

123456789
  1. # frozen_string_literal: true
  2. class LinesValidator < ActiveModel::EachValidator
  3. def validate_each(record, attribute, value)
  4. return if value.blank?
  5. record.errors.add(attribute, :too_many_lines, limit: options[:maximum]) if options[:maximum].present? && value.split.size > options[:maximum]
  6. end
  7. end