Add rows validation

This commit is contained in:
sokie
2026-01-13 13:50:12 +01:00
parent 30d3ee167e
commit c9b334ac4f

View File

@@ -42,6 +42,7 @@ class Import < ApplicationRecord
validates :number_format, presence: true, inclusion: { in: NUMBER_FORMATS.keys }
validates :rows_to_skip, numericality: { greater_than_or_equal_to: 0 }
validate :account_belongs_to_family
validate :rows_to_skip_within_file_bounds
has_many :rows, dependent: :destroy
has_many :mappings, dependent: :destroy
@@ -372,4 +373,15 @@ class Import < ApplicationRecord
errors.add(:account, "must belong to your family")
end
def rows_to_skip_within_file_bounds
return if raw_file_str.blank?
return if rows_to_skip.to_i == 0
line_count = raw_file_str.lines.count
if rows_to_skip.to_i >= line_count
errors.add(:rows_to_skip, "must be less than the number of lines in the file (#{line_count})")
end
end
end