Browse Source

refactor: use presence validation for la

pull/1034/head
natdeanlewissoftwire 4 years ago
parent
commit
a4d114cff8
  1. 9
      app/models/location.rb

9
app/models/location.rb

@ -1,7 +1,7 @@
class Location < ApplicationRecord class Location < ApplicationRecord
validates :postcode, on: :postcode, presence: { message: I18n.t("validations.location.postcode_blank") } validates :postcode, on: :postcode, presence: { message: I18n.t("validations.location.postcode_blank") }
validate :validate_postcode, on: :postcode validate :validate_postcode, on: :postcode
validate :validate_location_admin_district, on: :location_admin_district validates :location_admin_district, on: :location_admin_district, presence: { message: I18n.t("validations.location_admin_district") }
validates :name, on: :name, presence: { message: I18n.t("validations.location.name") } validates :name, on: :name, presence: { message: I18n.t("validations.location.name") }
validates :units, on: :units, presence: { message: I18n.t("validations.location.units") } validates :units, on: :units, presence: { message: I18n.t("validations.location.units") }
validates :type_of_unit, on: :type_of_unit, presence: { message: I18n.t("validations.location.type_of_unit") } validates :type_of_unit, on: :type_of_unit, presence: { message: I18n.t("validations.location.type_of_unit") }
@ -421,13 +421,6 @@ class Location < ApplicationRecord
end end
end end
def validate_location_admin_district
if location_admin_district == "Select an option"
error_message = I18n.t("validations.location_admin_district")
errors.add :location_admin_district, error_message
end
end
def validate_startdate def validate_startdate
unless startdate.between?(Time.zone.local(1900, 1, 1), Time.zone.local(2200, 1, 1)) unless startdate.between?(Time.zone.local(1900, 1, 1), Time.zone.local(2200, 1, 1))
error_message = I18n.t("validations.location.startdate_out_of_range") error_message = I18n.t("validations.location.startdate_out_of_range")

Loading…
Cancel
Save