Skip to content

Instantly share code, notes, and snippets.

@romulostorel
Last active December 15, 2015 07:09
Show Gist options
  • Save romulostorel/5221787 to your computer and use it in GitHub Desktop.
Save romulostorel/5221787 to your computer and use it in GitHub Desktop.
module ActiveRecord
module PreventChangeCloseAcademicYearDependents
def self.included(base)
base.before_destroy :validate
base.validate :validate, :on => :update
end
def validate
if (respond_to? :academic_year) && (academic_year_is_closed?)
errors.add(:base, :academic_year_is_closed)
end
end
private
def academic_year_is_closed?(academic_year_repository = AcademicYear)
academic_year_repository.find(academic_year.id).closed?
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment