|
|
|
@ -8,14 +8,15 @@ class Event < ActiveRecord::Base
|
|
|
|
|
class_name: City
|
|
|
|
|
|
|
|
|
|
validates :title, presence: true
|
|
|
|
|
validate :end_after_start
|
|
|
|
|
validates :description, presence: true
|
|
|
|
|
validates :city, presence: true
|
|
|
|
|
validates :related_region, presence: true
|
|
|
|
|
validates :url, presence: true, format: %r{\Ahttps?:\/\/.*\z}
|
|
|
|
|
validates :url, presence: true, format: %r{\Ahttps?:\/\/.*\..*\z}
|
|
|
|
|
validates :contact, presence: true
|
|
|
|
|
validates :contact, email: true
|
|
|
|
|
validates :submitter, email: true
|
|
|
|
|
validate :end_after_start
|
|
|
|
|
validates :tags, presence: false, format: /\A[\p{Alnum}\s-]*\z/
|
|
|
|
|
|
|
|
|
|
geocoded_by :full_address, lookup: :nominatim
|
|
|
|
|
# after_validation :geocode, if: -> (obj) { obj.address_changed? }
|
|
|
|
@ -42,6 +43,11 @@ class Event < ActiveRecord::Base
|
|
|
|
|
scope :tag, -> tag { where 'tags like ?', "%#{tag}%" }
|
|
|
|
|
scope :geo, -> { where 'latitude is not null and longitude is not null' }
|
|
|
|
|
|
|
|
|
|
before_validation do
|
|
|
|
|
# Tags are always downcased
|
|
|
|
|
self.tags = tags.mb_chars.downcase if tags
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
before_validation on: :create do
|
|
|
|
|
self.submission_time = DateTime.now
|
|
|
|
|
self.decision_time = DateTime.now
|
|
|
|
|