Skip to content

Instantly share code, notes, and snippets.

@jondahl
Created March 3, 2009 19:56
Show Gist options
  • Save jondahl/73490 to your computer and use it in GitHub Desktop.
Save jondahl/73490 to your computer and use it in GitHub Desktop.
Rake task to look for all invalid ActiveRecord records in a Rails application
namespace :db do
namespace :data do
desc "Find all invalid ActiveRecord records"
task :invalid_records => :environment do
models = Object.subclasses_of(ActiveRecord::Base)
models.each do |model|
begin
model.all.each do |record|
if !record.valid?
puts "#{model} #{record.id} is invalid: #{record.errors.full_messages.to_sentence}"
end
end
rescue Exception => e
puts "Error checking class #{model} (#{e})"
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment