Tag: 调试

在所有视图中调试输出

我目前正在开发一个新的Rails 3应用程序。 控制器中定义的所有实例变量将在我的视图中自动调试。 这在开发和生产模式中都会发生。 尽管这很有用,但我真的很想摆脱它,因为它会部分地破坏HTML布局。 例如,我在我的控制器中有索引操作: respond_with(@articles = Article.published.order(“created_at DESC”).page(params[:page]).per(5)) 在视图中,您将自动看到类似于的输出的内容,尽管我从不在视图中调用inspect或debug。 用于演示整个问题的示例图片: http://www.diigo.com/item/image/16wox/padm?size=o 我的Gemfile看起来像这样: https ://gist.github.com/1080104

如何在Aptana Studio 3.0.9中使用bundle exec来运行调试器?

Aptana似乎从sh shell开始。 所以我试图切换到zsh ,并执行命令来启动rails应用程序。 我已经更改了我的调试可执行文件,以便它运行带有以下内容的unix可执行文件: #!/usr/bin/env ruby exec(“zsh | (echo $SHELL && [[ -s ‘$HOME/.rvm/scripts/rvm’ ]] && source ‘$HOME/.rvm/scripts/rvm’ && rvm use 1.8.7@tinderbox && (bundle exec script/server -p3001 &))”) 因此,当我从工具栏上的调试菜单中单击我的调试可执行文件时,会出现调试透视图,并显示它 myApp [Ruby Application] Ruby /usr/bin/ruby 正在运行但尚未终止。 但当我进入我的浏览器并输入0.0.0.0:3001时,我得到“哎呀!谷歌Chrome无法连接到localhost:3001” – 这意味着服务器无法运行。 我将可执行文件的输出设置为我桌面上的文件,这是每次运行时发生的事情: Fast Debugger (ruby-debug-ide 0.4.16, ruby-debug-base 0.10.4) listens on 127.0.0.1:55306 /bin/zsh 注意:我使用bash和zsh获得相同的结果 到底是怎么回事? 以及如何让我的命令工作?

从ruby方法中获取内容

我使用jruby运行一堆ruby脚本,虽然我使用的是纯ruby部分。 有时难以从输出中确切地发现究竟发生了什么或者确实出现了什么问题。 我想在每个方法的std中得到类似的东西:在方法A的方法A中输入 现在我肯定可以把这些评论放在每一种方法中……感觉非常错误。 有没有办法在更详细的情况下运行ruby以在我的日志中获取此信息。 希望我会避免使用很多gem等..因为这些是在一些托管服务器上,我将不得不花一些时间来获得更多的s / f。 希望有些东西可以作为jruby本身的一部分 谢谢!

权限被拒绝从Ruby gem运行方法

我正在使用名为IMGKit的gem,当我在控制台中使用gem的to_img方法时,我收到此错误: IMGKit::CommandFailedError: Command failed: /rubyprograms/search –format jpg http://google.com -: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/open3.rb:67:in `exec’: Permission denied – /rubyprograms/search (Errno::EACCES) from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/open3.rb:67:in `popen3′ from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/open3.rb:53:in `fork’ 我不知道发生了什么事。 这是to_img方法: def to_img(format = nil) append_stylesheets set_format(format) result = nil stderr_output = nil Open3.popen3(*command) do |stdin,stdout,stderr| stdin << (@source.to_s) if @source.html? stdin.close result = stdout.gets(nil) result.force_encoding("ASCII-8BIT") if result.respond_to? :force_encoding stderr_output = stderr.readlines.join […]

如何在Heroku上调试“检测资产错误:预编译任务”问题

当推送到Heroku时,我们在输出中看到以下行: … Error detecting the assets:precompile task … 然后该应用程序将成功部署,但它将没有任何资产。 这非常令人沮丧,因为没有出现错误,我们也不知道可能会发生什么。 日志没有任何暗示。 这是推送终端输出的尾部 : Your bundle is complete! It was installed into ./vendor/bundle Cleaning up the bundler cache. —–> Writing config/database.yml to read from DATABASE_URL Error detecting the assets:precompile task —–> Discovering process types Procfile declares types -> (none) Default types for Ruby/Rails -> console, rake, […]

如何使用键盘进入运行rails应用程序的ruby-debug?

我正在使用Rails 2.3上的bundle exec rdebug script/server运行ruby-debug。 当我按Ctrl-C ,它退出整个程序和调试器。 我希望它停止执行程序并将我带入调试器会话。 我试过catch Interrupt但它没有用。 当我使用Ctrl-C停止轨道时,是否会调用exception,这样可以很好地用于此目的? 或者还有另一种方式吗? 我想要的是相当于在Visual Studio中按下Break(暂停)按钮(我还没有使用Rails IDE完成此操作)。

我如何在Capybara w / selenium中使用ruby-debug

我们让Capybara使用selenium驱动程序但是当我尝试在步骤中使用“调试器”时它不太有效。 例如,在调试控制台中输入’page’有效,但输入’page.body’挂起。 在尝试使用akephalos驱动程序的调试器时,我们也很奇怪。 使用akephalos我们无法输入调试提示…实际上我们可以,但是你必须多次按键才能在终端中随机显示一个字母。 做’Ctrl-C’让我们输入,但是我们得到了’DRb connection … something’之类的错误(抱歉再也没有确切的错误)。 我认为问题是像selenium和akephalos这样的驱动程序在同一个进程中运行测试和服务器,它会混淆ruby-debug。 我将尝试单独运行服务器(脚本/服务器测试)并使用Capybara.app_host =’http:// localhost:3000’来查看是否会产生影响。 我尝试使用akephalos,但由于它刚刚启动了另一个进程内服务器,所以无法实现。 是否有人使用与Capybara和selenium的ruby-debug? 这对其他人有用吗? 我错过了一些明显的东西吗

如何使用rails console调试并放入应用程序

我想通过rails控制台打开irb打印的一些线条。 我已经看到很多关于如何实现它的SO问题。 但是我没有得到什么。 下面是代码 – def show puts ‘in show method’ @post = Feed.find_by_id params[:id] puts @post.inspect redirect_to root_path unless @post.present? end 现在我已经通过命令rails server打开了rails server 。 另外,在另一个终端我给命令rails console ,它打开了irb提示符。 在浏览器中我运行localhost:3000/posts/82它会给出正确的post,但控制台中没有显示任何内容。 我错过了什么步骤? 我想在调用特定方法时在控制台中打印一些东西。

Rails日志文件中的输出行号

从调试的Rails指南 ,我发现我可以使用这个简单的方法自定义输出到我的日志文件: logger.debug “Person attributes hash: #{@person.attributes.inspect}” 我决定使用它来跟踪变量如何变化并通过流量控制。 我希望能够看到我的代码的行号,其中调用了logger#debug方法。 像这样的东西: logger.debug “Person attributes hash: #{@person.attributes.inspect} from line #{LINE_NUMBER_VAR}”

在rake任务中使用open-uri 404错误…导致它的原因是什么?

我有一个rake任务,从API获取JSON数据,解析它,并将其保存到数据库: task :embedly => :environment do require ‘json’ require ‘uri’ require ‘open-uri’ Video.all.each do |video| json_stream = open(“http://api.embed.ly/1/oembed?key=08b652e6b3ea11e0ae3f4040d3dc5c07&url=#{video.video_url}&maxwidth=525”) ruby_hash = JSON.parse(json_stream.read) thumbnail_url = ruby_hash[‘thumbnail_url’] embed_code = ruby_hash[‘html’] video.update_attributes(:thumbnail_url => thumbnail_url, :embed_code => embed_code) end end 当我运行rake任务时,我在堆栈跟踪中得到此错误,我不知道是什么导致它: rake aborted! 404 Not Found /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/open-uri.rb:277:in `open_http’ /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/open-uri.rb:616:in `buffer_open’ /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/open-uri.rb:164:in `open_loop’ /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/open-uri.rb:162:in `catch’ /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/open-uri.rb:162:in `open_loop’ /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/open-uri.rb:132:in `open_uri’ /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/open-uri.rb:518:in `open’ […]