How to watch a Rails object in the console
Is there a way to watch a Rails object in the console?
I can of course keep manually repeating a command and checking for changes, but it would be nice to be able to do something like watch Booking.find_by_id(39)
and be notified of the changes.
To give a bit of c开发者_StackOverflow社区ontext I've got a DelayedJob in heroku which I want to monitor the progress of.
It would be nice also to be able to watch objects in the console while performing actions on them in the web app.
I'm going to guess that for the specific problem you're talking about, which sounds like progress-monitoring of a DelayedJob, there is a gem available to do that for you. But as a more general answer to your question... you're using a programming language, so make use of it! :)
def watch(&block)
Thread.new do
loop do
puts block.call.inspect
sleep 2
end
end
end
watch { Booking.find_by_id(39) }
精彩评论