How to debug a plugin / gem? (with useful notes to setup and use ruby-debug gem)

这一生的挚爱 提交于 2019-12-07 07:10:19

问题


Is there a way like how we debug models / controllers with logger.debug? Or even a better method?

Thank you!

Edit 1

Using ruby-debug seems like a steep learning curve for me, could anyone point me something similar to logger.debug, perhaps?

Edit 2

Alright, I think I started to get a grasp on ruby-debug.

Some useful notes for newbies to setup & use ruby-debug:

gem install ruby-debug
in config/environments/development.rb add

include 'ruby-debug'

then just above the code you want to debug add:

debugger

if you need to debug third party plugin / gem, use

include 'ruby-debug'
debugger

just use ruby script/server to run, no need to add --debugger

Edit 3

This plugin really helps me out in understanding the flow of Rails application. I highly recommend this to any newbies going pro!

Simply setup ruby-debug, then put debugger code anywhere in your controller under the action your application requested. You will then find great revelation!


回答1:


I highly recommend you learn to use ruby-debug. You can install it by doing:

gem install ruby-debug

You can then add a debugger statement to your code either in the plugin code or where your code calls the plugin, step through it, and see what's going wrong.

I also personally use these settings which makes it a bit easier to use - put them in a ~/.rdebugrc file.

set autoeval
set autolist
set autoreload


来源:https://stackoverflow.com/questions/3585985/how-to-debug-a-plugin-gem-with-useful-notes-to-setup-and-use-ruby-debug-gem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!