Debug Output For Migrations in Ruby on Rails

Posted by Ben Reubenstein Tue, 31 Jul 2007 13:04:00 GMT

Today I was doing some massive migrations that rocked the very foundations of an app I am working on. Problem was that during the migration I was moving objects around the database and validations were failing for my saves. To get some debugging going, I started out trying to write to the logger, with some good ol' logger.debug, but that does not work within a migration. To output information in a migration, use puts. So for example to see all the errors that prevented object g from being saved:
class MyMigration < ActiveRecord::Migration
  def self.up
    g = G.new(:name => "name" )
    if g.save
      #More object manipulation here
    else
      g.errors.each do |x|
        puts x
      end
    end
  end

  def self.down
    #Down Method Code Here
  end
end

Posted in  | Tags , , ,  | 2 comments

Comments

  1. Willis said 16 days later:

    What a nerd. U rock!

  2. Nic Heavenly Johnson said 3 months later:

    You rule! Good old fashioned terminal dump debugging! Thank you very much!

   Comment Markup Help Preview comment