Skip to content

Instantly share code, notes, and snippets.

@terrbear
Created September 13, 2011 20:01
Show Gist options
  • Save terrbear/1214944 to your computer and use it in GitHub Desktop.
Save terrbear/1214944 to your computer and use it in GitHub Desktop.
form_names = AdHocTemplate.active.map(&:canonical_name)
states = %w(pending in_progress submitted)
Contact.all.each do |c|
form_names.each do |form|
forms = AdHocForm.where(:template_canonical_name => form, :contact_id => c.id).all
next if forms.empty?
forms = forms.to_a.sort{|a, b| states.index(a.aasm_state) <=> states.index(b.aasm_state)}
forms.pop
forms.each{|f| f.destroy}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment