Skip to content

Instantly share code, notes, and snippets.

@Mikr0Tik
Created October 13, 2008 11:27
Show Gist options
  • Save Mikr0Tik/16522 to your computer and use it in GitHub Desktop.
Save Mikr0Tik/16522 to your computer and use it in GitHub Desktop.
Form-model form.rb:
before_destroy :validate_assoc
def validate_assoc
if inactive && !(towers = Tower.find(:all, :conditions=>{:form_id=>id})).blank?
towers.each{|tower| errors.add(:inactive, tower )}
false
end
end
def destroy_by_person_with_validation person_id
self.attributes = self.attributes.update({:inactive=>true, :person_id=>person_id})
callback(:before_destroy)
save(false)
callback(:after_destroy)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment