seeds 데이터 validation 스킵
상황
class WarRequestCreateValidator < ActiveModel::Validator
def validate(record)
@start_date = record.start_date.to_date
@end_date = record.end_date.to_date
@war_time = record.war_time
errors = record.errors
if @start_date.nil? || @end_date.nil?
errors.add(:base, "전쟁 시작일을 입력해주세요")
elsif start_date_after_max_start_date?
errors.add(:base, "전쟁 시작일은 60일 이내로 설정해야 합니다.")
elsif start_date_after_tomorrow?
errors.add(:base, "전쟁 시작일은 내일 이후여야 합니다.") # 여기가 문제다!!!
elsif end_date_after_start_date?
errors.add(:base, "전쟁 종료일은 시작일 이후여야 합니다.")
elsif end_date_after_max_end_date?
errors.add(:base, "전쟁 종료일은 시작일 기준 7일 이내여야 합니다.")
elsif invalid_war_time?
errors.add(:base, "전쟁 시작 시각은 9시부터 22시 사이여야 합니다.")
end
end
...
end해결
Last updated