Created
March 3, 2009 19:56
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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