我正在使用Pry和我的Rails应用程序.我binding.pry在我的模型中设置了一个循环来尝试调试问题.例如:
(1..100).each do |i|
binding.pry
puts i
end
Run Code Online (Sandbox Code Playgroud)
当我输入时quit,它会进入下一次迭代并再次停止.有没有办法走出循环所以我不必输入quit100次?
目前,我知道如何摆脱它的唯一方法是使用CTRL+ C并重新启动应用程序.
使用Pry in Rails,当我在代码binding.pry中遇到断点时
我想知道我是怎么来到这里的,谁打电话给我,打电话给他们等等.但奇怪的是我没有看到那个命令.有人知道吗?
当使用pry作为调试器时,我没有看到进入下一行的方法.我能找到的就是编辑方法并将binding.pry移动到下一行.有这样的功能吗?
22: def scan path
23: @last_line_had_text, @files_read, @hands_read = nil, 0, 0
24: Find.find(path){ |file_name|
=> 25: binding.pry
26: read_file(file_name) if file_name.include?(".txt")
27: }
28: end
Run Code Online (Sandbox Code Playgroud) 我正在编写我的第一个Sinatra应用程序,并希望使用Pry来检查/调试应用程序中正在发生的一些事情.我之前没有使用过Pry,但我想尝试一下.我如何开始在我的Sinatra应用程序中使用Pry?
我在我的Rails控制台中使用Pry gem,但是pry风味的rails-console似乎已经失去了重载!重新加载模型和东西的方法.
以下是我启动pry控制台的方法
c:\rails\app> pry -r ./config/environment
Run Code Online (Sandbox Code Playgroud)
谢谢
我在开发环境中的docker容器中运行了一个rails应用程序.
当我尝试通过binding.pry在代码中放置某个位置并附加到容器来调试它时,我可以看到pry输出中的提示但它不会暂停在它上面,我无法像它没有docker容器那样与它交互.
那么我该如何调试容器化的应用程序呢?
我正在使用guard-rails运行我的rails服务器,我的问题是当我添加binding.pry时我无法访问REPL
From: /home/martinr/code/app/controllers/tools_controller.rb @ line 2 ToolsController#index:
2: def index
=> 3: binding.pry
4: @end_date = Date.today.to_s
5: @start_date = Date.today.months_ago(3).to_s
7: end
[1] pry(#<ToolsController>)>
Run Code Online (Sandbox Code Playgroud)
没有REPL,我如何使用护栏撬?
我的Gemfile文件看起来像这样
group :development, :test do
gem 'pry-rails' # for better console debugging
gem 'pry-debugger'
gem 'rb-inotify'
gem 'sqlite3'
end
Run Code Online (Sandbox Code Playgroud)
我的Guardfile:
guard 'rails', :debugger => true do
watch('Gemfile.lock')
watch(%r{^(config|lib)/.*})
end
Run Code Online (Sandbox Code Playgroud) 嗨我已经安装了Pry来做一些很棒的调试并且之前有它工作但是当我用'next'进入代码时我得到以下错误:
SyntaxError: (eval):2: Can't escape from eval with next
Run Code Online (Sandbox Code Playgroud)
正在使用的代码:
def create
binding.pry
build_resource(sign_up_params)
if resource.save
yield resource if block_given?
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_flashing_format?
sign_up(resource_name, resource)
respond_with resource, :location => after_sign_up_path_for(resource)
else
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format?
expire_data_after_sign_in!
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords resource
respond_with resource
end
end
Run Code Online (Sandbox Code Playgroud)
其他人遇到过这个问题吗?
我正在跟踪一个名为pry的红宝石宝石上的屏幕.在8:10,使用.tree命令,我相信这是一个Unix命令.
它似乎不适用于我的系统:
[24] pry(main)> .tree
\Error: there was a problem executing system command: tree
Run Code Online (Sandbox Code Playgroud)
我已经将问题追溯到这里,其中pry引用了一个shell命令:
Pry::CommandSet.new do
command(/\.(.*)/, "All text following a '.' is forwarded to the shell.", :listing => ".<shell command>") do |cmd|
if cmd =~ /^cd\s+(.+)/i
dest = $1
begin
Dir.chdir File.expand_path(dest)
rescue Errno::ENOENT
output.puts "No such directory: #{dest}"
end
else
if !system(cmd)
output.puts "Error: there was a problem executing system command: #{cmd}"
end
end
end
Run Code Online (Sandbox Code Playgroud)
从bash的上下文我尝试使用命令树没有运气:
projects/sms(apps2)$ tree
-bash: tree: command …Run Code Online (Sandbox Code Playgroud) 在Ruby中,我可以binding.pry在我的代码中的任何位置键入,在执行时,我的控制台将进入REPL,我可以访问所有局部变量,可以进行更改,并执行任意代码.
例:
# foo.rb
require 'pry'
n = 5
binding.pry
puts "your number is #{n}"
Run Code Online (Sandbox Code Playgroud)
当我运行它:
$ ruby foo.rb
From: /Users/cgenco/Desktop/foo.rb @ line 4 :
1: # foo.rb
2: require 'pry'
3: n = 5
=> 4: binding.pry
5: puts "your number is #{n}"
[1] pry(main)> n = 100
=> 100
[2] pry(main)> exit
your number is 100
Run Code Online (Sandbox Code Playgroud)
这是一个令人难以置信的调试工具,特别是对于需要复杂设置的情况:我可以binding.pry在现场键入我需要更多代码,弄乱,找出需要编写的代码,然后将抛光的代码添加到实际的源代码中.
在浏览器控制台中是否有像jy这样的工具?