Skip to content

Commit

Permalink
Mark school fields as required and update their locations
Browse files Browse the repository at this point in the history
  • Loading branch information
cycomachead committed Aug 26, 2024
1 parent c9130fc commit 456af56
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app/javascript/packs/schools.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ let create_school = function (input, callback) {
selectizeCallback = null;
$('#teacher_school_id').val(original_school_id);
}
toggle_required(['name', 'city', 'state', 'website'], true);
// TODO: This list should match the model attributes.
toggle_required(['name', 'city', 'state', 'website', 'grade_level', 'school_type'], true);
$("#school_form").hide();
});
};
Expand Down
8 changes: 7 additions & 1 deletion app/models/school.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ class School < ApplicationRecord
validates :state, presence: true, if: -> { country == "US" }
validates :state, inclusion: { in: VALID_STATES }, if: -> { country == "US" }
validates_format_of :website, with: /.+\..+/, on: :create
validates :grade_level, presence: true
validates :school_type, presence: true

before_save :update_gps_data, if: -> { lat.nil? || lng.nil? }
before_save :update_gps_data, if: -> { lat.nil? || lng.nil? || location_changed? }

has_many :teachers
scope :validated, -> { where("teachers_count > 0") }
Expand Down Expand Up @@ -124,6 +126,10 @@ def self.all_maps_data
end

private
def location_changed?
city_changed? || state_changed? || country_changed?
end

def prefix_url(url)
return unless url
url.match?(/^https?:/) ? url : "https://#{url}"
Expand Down

0 comments on commit 456af56

Please sign in to comment.