@@ -19,6 +19,7 @@ class Event < ApplicationRecord
1919 include WithTimezone
2020
2121 before_validation :fix_keywords , on : :create , if : :scraper_record
22+ before_validation :presence_default
2223 before_save :check_country_name # :set_default_times
2324 before_save :geocoding_cache_lookup , if : :address_will_change?
2425 after_save :enqueue_geocoding_worker , if : :address_changed?
@@ -124,6 +125,7 @@ class Event < ApplicationRecord
124125 validates :latitude , numericality : { greater_than_or_equal_to : -90 , less_than_or_equal_to : 90 , allow_nil : true }
125126 validates :longitude , numericality : { greater_than_or_equal_to : -180 , less_than_or_equal_to : 180 , allow_nil : true }
126127 # validates :duration, format: { with: /\A[0-9][0-9]:[0-5][0-9]\z/, message: "must be in format HH:MM" }, allow_blank: true
128+ validates :presence , inclusion : { in : presences . keys , allow_blank : true }
127129 validate :allowed_url
128130 clean_array_fields ( :keywords , :fields , :event_types , :target_audience ,
129131 :eligibility , :host_institutions , :sponsors )
@@ -495,4 +497,8 @@ def fix_keywords
495497 end
496498 end
497499 end
500+
501+ def presence_default
502+ self . presence = :onsite if presence . blank?
503+ end
498504end
0 commit comments