Created
August 20, 2014 23:30
-
-
Save malclocke/9ca1006f3e7f0b8128c5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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