开发者

In Rails, how drop into debugger when a condition is met

开发者 https://www.devze.com 2023-03-26 20:31 出处:网络
Let\'s say that foo is created, changed and saved many times when a program runs. Usually, foo.bar == \"sensible value\", but occassionally, foo.bar == \"crazy value\".

Let's say that foo is created, changed and saved many times when a program runs.

Usually, foo.bar == "sensible value", but occassionally, foo.bar == "crazy value".

Is there some way I can run rails server --debugger, and have it only drop into the开发者_StackOverflow社区 debugging console at the point where foo.bar == "crazy value"?


Have you tried

if foo.bar == "crazy value"
  require 'ruby-debug'; debugger
end

This should place a breakpoint that triggers when you run bundle exec rails server normally, and only when foo.bar has the value you (don't) want.

If you are using bundler, and Ruby 1.9 make sure you have

gem 'ruby-debug19', :require => 'ruby-debug'

in your Gemfile (in the development and test group).

0

精彩评论

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

关注公众号