Skip to content

Instantly share code, notes, and snippets.

@malclocke
Created August 20, 2014 23:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malclocke/9ca1006f3e7f0b8128c5 to your computer and use it in GitHub Desktop.
Save malclocke/9ca1006f3e7f0b8128c5 to your computer and use it in GitHub Desktop.
desc <<-EOT
Display the id and error messages of all invalid instances of each model in
model_classes, which should be a comma separated list of model names. If
model_classes is blank all models will be reported.
EOT
task :validate_models, [:models] => :environment do |t, args|
model_classes = if args[:models]
args[:models].split(',').map(&:constantize)
else
Rails.application.eager_load!
ActiveRecord::Base.descendants
end
model_classes.each do |model_class|
$stderr.puts "# #{model_class.name}"
model_class.all.reject(&:valid?).each do |model|
puts "%s:%d:%s" % [model_class.name, model.id, model.errors.full_messages]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment