开发者

Debugging migrations in rails 3 using ruby-debug?

How do I debug my migrations using 开发者_如何学Goruby-debug in rails 3?

running rake db:migrate does not seem to trigger any debugger command as in Rails 2. And rake db:migrate --debugger does not work either.

Thanks.


I was able to debug a migration by doing the following

Add ruby-debug to Gemfile

gem 'ruby-debug19'

In the migration add require 'ruby-debug' and execute debugger in the line you want to stop. For example

require 'ruby-debug'

class CreatePeople < ActiveRecord::Migration

  def self.up
    debugger
    create_table :people do |t|
      t.string :name
      t.String :email

      t.timestamps
    end
  end

  def self.down
    drop_table :people
  end
end

then run rake db:migrate or any other db command. For example

~/dev/ruby/migrate$ rake db:migrate
(in /Users/augusto/dev/ruby/migrate)
==  CreatePeople: migrating ===================================================
/Users/augusto/dev/ruby/migrate/db/migrate/20110212134536_create_people.rb:7
create_table :people do |t|
(rdb:1) list
[2, 11] in /Users/augusto/dev/ruby/migrate/db/migrate/20110212134536_create_people.rb
   2  
   3  class CreatePeople < ActiveRecord::Migration
   4  
   5    def self.up
   6      debugger
=> 7      create_table :people do |t|
   8        t.string :name
   9        t.String :email
   10  
   11        t.timestamps
(rdb:1)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜