eclipse 如何调试 Rails 应用程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/963292/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 13:46:27  来源:igfitidea点击:

How do you debug a Rails application?

javaruby-on-railsrubyeclipsenetbeans

提问by

Is it possible to debug a Rails application in a similar way to a Java application - setting breakpoints and stepping into the code?

是否可以以类似于 Java 应用程序的方式调试 Rails 应用程序 - 设置断点并进入代码?

What are the best tools for this?

什么是最好的工具?

I have a hybrid Java/Ruby on Rails application which I can run in Eclipse or Netbeans.

我有一个混合 Java/Ruby on Rails 应用程序,可以在 Eclipse 或 Netbeans 中运行。

I would like to step into some code in this app and try to figure out the cause of a problem I'm having.

我想进入这个应用程序中的一些代码并尝试找出我遇到的问题的原因。

In Eclipse if I set a breakpoint in my blog_controllerand then choose the 'Debug' button, it seems to use the ruby-debug-idegem to execute the code but I get this unhelpful output and no option to step into any source:

在 Eclipse 中,如果我在我的设置中设置断点blog_controller然后选择“调试”按钮,它似乎使用ruby-debug-idegem 来执行代码,但我得到这个无用的输出并且没有选项可以进入任何源:

Fast Debugger (ruby-debug-ide 0.4.5) listens on localhost:56726
    ./war/WEB-INF/app/controllers/blog_controller.rb:1
    C:/Ruby18/lib/ruby/gems/1.8/gems/ruby-debug-ide-0.4.5/lib/ruby-debug.rb:101:in `debug_load'
    C:/Ruby18/lib/ruby/gems/1.8/gems/ruby-debug-ide-0.4.5/lib/ruby-debug.rb:101:in `debug_program'
    C:/Ruby18/lib/ruby/gems/1.8/gems/ruby-debug-ide-0.4.5/bin/rdebug-ide:82
    C:/Ruby18/bin/rdebug-ide:19:in `load'
    C:/Ruby18/bin/rdebug-ide:19
Uncaught exception: uninitialized constant ApplicationController

I'm not sure if I'm doing something wrong or if this is all I can expect.

我不确定我是否做错了什么,或者这是否就是我所能期望的。

采纳答案by ski

There's a guide herefor Netbeans.

有一个指导这里的Netbeans的。

回答by csexton

The debugger I use the most is the ruby-debuggem, which is a gdb-esque command line debugger. Once you learn a few commands it is very quick and effective, and provides you with some handy features like being able to fire up irbin the context of your program and make on-the-fly changes.

我使用最多的调试器是ruby-debuggem,它是一个 gdb 风格的命令行调试器。一旦你学会了一些命令,它就会非常快速和有效,并为你提供一些方便的功能,比如能够irb在你的程序上下文中启动并进行即时更改。

And being command line based it comes in handy when you need to debug a on a remote server.

当您需要在远程服务器上调试 a 时,基于命令行的它会派上用场。

回答by Pete TerMaat

You can expect more.I have used Aptana's RadRailsversion of Eclipse to debug a Rails app as you describe--setting breakpoints and stepping through the code.

你可以期待更多。我已经使用 Aptana 的RadRails版本的 Eclipse 来调试 Rails 应用程序,正如您所描述的那样——设置断点并逐步执行代码。

You may be doing something wrong.It looks as if it is trying to debug an individual controller file, rather than debugging the Rails app. When I try to execute a controller file from the command line, I get a similar message:

你可能做错了什么。它看起来好像是在尝试调试单个控制器文件,而不是调试 Rails 应用程序。当我尝试从命令行执行控制器文件时,我收到类似的消息:

C:\workspace\myapp\app\controllers>ruby users_controller.rb
users_controller.rb:1: uninitialized constant ApplicationController (NameError)

In Aptana RadRails, I choose Run > Debug As > Ruby Applicationto debug the app.

在 Aptana RadRails 中,我选择Run > Debug As > Ruby Application调试应用程序。

回答by csexton

For the vim users I strongly recomend looking into the vim-ruby-debugger, which fits in great with Tim Pope's rails.vim scripts.

对于 vim 用户,我强烈建议查看vim-ruby-debugger,它非常适合 Tim Pope 的 rails.vim 脚本。

It gives you a handy :Rdebuggercommand, allows you to set breakpoints and open a split window to display variable values.

它为您提供了一个方便的:Rdebugger命令,允许您设置断点并打开一个拆分窗口以显示变量值。

回答by csexton

maybe not relevant, but I wanted to post somewhere: got the error: "undefined method `run_init_script' for Debugger:Module" running the debugger in rails 2.3.2. Did a sudo gem install ruby-debug and the problem went away.

也许不相关,但我想在某处发布:得到错误:“未定义方法`run_init_script' for Debugger:Module”在 rails 2.3.2 中运行调试器。是否 sudo gem install ruby​​-debug 并且问题消失了。

回答by Ryan Bigg

Debugging? That's just knowing where to look in the case of Ruby (and by extension, Rails) most of the time.

调试?大多数时候,这只是知道在 Ruby(以及通过扩展,Rails)的情况下在哪里查看。

The problem in this case is that you probably still have your ApplicationControllercalled application.rbwhere it should be renamed to application_controller.rb.

在这种情况下的问题是,您可能仍然有您ApplicationController调用的application.rb,它应该重命名为application_controller.rb

回答by Ryan Bigg

Actually, I had the same problem with Aptana. Run > Debug As > Ruby Applicationjust doesn't work. I finally made the debugger work by going to the Serverstab, and then start the server in debug mode. After that, set some breakpoints and trigger the corresponding action. Hope this helps.

实际上,我在使用 Aptana 时遇到了同样的问题。Run > Debug As > Ruby Application只是不起作用。我最终通过转到Servers选项卡使调试器工作,然后在debug mode. 之后,设置一些断点并触发相应的动作。希望这可以帮助。

回答by Ryan Bigg

Debuggin in rails is simple if you know how to read the error stacktrace!! But if you need to explicitly watch out the values during the runtime then u can use the rails breakpointer.Below is the link to how-to on breakpointer ..hope this helps!!!

如果您知道如何读取错误堆栈跟踪,那么 Rails 中的调试很简单!!但是,如果您需要在运行时明确注意这些值,那么您可以使用 rails 断点器。下面是断点器操作方法的链接..希望这有帮助!!!

http://destiney.com/blog/rails-breakpointer

http://destiney.com/blog/rails-breakpointer

回答by Mike Woodhouse

I can't speak for Eclipse (never worked well for me) or Aptana (not tried) but from experience I can say that both NetBeansand RubyMinewill do what you want. I both cases you should probably make sure that the ruby-debug-base and ruby-debug-ide gems are up-to-date: RubyMine in particular didn't work for me until that was done.

我不能说 Eclipse(对我来说从来没有奏效)或 Aptana(没有尝试过),但根据经验,我可以说NetBeansRubyMine都可以做你想做的事。在这两种情况下,您都应该确保 ruby​​-debug-base 和 ruby​​-debug-ide gems 是最新的:在完成之前,RubyMine 特别对我不起作用。

回答by happythenewsad

I'd recommend just setting up breakpoints (I actually just putsto console) for 99% of debugging with RoR - this method is simple and usable across any IDE, so you never need to learn how a new debugger works.

我建议在使用 RoR 进行 99% 的调试时只设置断点(我实际上只是设置到控制台) - 这种方法很简单并且可以在任何 IDE 中使用,因此您永远不需要了解新调试器的工作原理。