The personal finance app for everyone (by everyone)
Ruby
Add rows validation
sokiec9b334ac4f1e
diff --git a/app/models/import.rb b/app/models/import.rbindex cb42a95f43..86ea588266 100644--- a/app/models/import.rb+++ b/app/models/import.rb@@ -42,6 +42,7 @@ class Import < ApplicationRecordvalidates :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_boundshas_many :rows, dependent: :destroyhas_many :mappings, dependent: :destroy@@ -372,4 +373,15 @@ class Import < ApplicationRecorderrors.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+ endend