When I look for a problem, for example with a specific ActiveRecord object, I often find myself doing the following on my production system:
# RAILS_ENV=production bundle exec
irb(main)> article = Article.find(123)
=> #<Article id: 123, title: "Foobar">
irb(main)> article.do_something(3)
NoMethodError: undefined method `id' for nil:NilClass
Sometimes I can't reproduce, why the line article.do_something(3)
throws an error, so I want to debug it directly on my server, in production mode.
The problem now is: How do I step into the method #do_something
with the argument 3
on the object / instance article
?
Of course, one could set a breakpoint in that method, reload production and let all their customers wait on that breakpoint till I'm done debugging... But that wouldn't be the best idea.
So, is there a way to debug into a method of a specific instance from a running irb / pry session? (both would be ok)