【问题标题】:Pry not loading local app environment in Rails 4.2撬不加载 Rails 4.2 中的本地应用程序环境
【发布时间】:2016-08-09 00:31:18
【问题描述】:

我最近安装了 pry 来替换我的 irb。起初它运行良好,但现在每次我运行 pry 时它根本无法识别本地应用程序环境。我得到如下信息:

[3] pry(main)> show-models
NameError: undefined local variable or method `show' for main:Object
from (pry):2:in `__pry__'

我已尝试卸载并重新安装 pry-rails gem,并将以下代码添加到初始化程序文件中:

Rails.application.configure do
  # Use Pry instead of IRB
  silence_warnings do
    begin
      require 'pry'
      IRB = Pry
    rescue LoadError
    end
  end
end

对这可能是什么有什么想法?我似乎找不到这方面的任何信息。

我的 gem 文件如下所示:

group :development, :test do

  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug'
  gem 'pry-rails'
  gem 'pry-byebug'

end

【问题讨论】:

    标签: ruby-on-rails ruby pry


    【解决方案1】:

    您可能使用 pry 命令运行 Pry,而您应该使用 rails console 命令(确保从 Rails 应用程序目录运行它)。如果这对您不起作用,请尝试 bin/rails consolebundle exec rails console 命令。

    【讨论】:

    • 当我运行 rails console 时出现错误:lorenzsell$ rails console Running via Spring preloader in process 39543 /usr/local/var/rbenv/versions/2.1.3/lib/ruby/2.1。 0/irb/completion.rb:11:in `': IRB 不是模块 (TypeError)
    • 删除你添加的初始化器。 pry-rails 不需要任何初始化程序即可工作[source]。
    【解决方案2】:

    我也用撬

    我还在使用像 show-models 这样的 pry 和未见过的命令。它对我也不起作用。而且我从不使用这样的命令。使用Model.all 工作正常。如果您使用的命令是撬的功能,我不知道。如果是这样,请访问其文档。我认为它的问题是由于您给出了错误的命令。

    【讨论】:

    • 不,Models.all 也不适合我。我收到类似的错误:[1] pry(main)> Models.all NameError: uninitialized constant Models from (pry):1:in `__pry__'
    • 抱歉没有模型只有 Model.all
    【解决方案3】:

    同时使用prybyebug 时遇到了一些不同的问题。

    我删除了byebug,一切都很好。

    希望它也能解决你的问题。

    我在 gemfile 中使用 gem 'pry' 而不是 gem 'pry-rails'

    【讨论】:

    • 我同时运行 pry 和 byebug 没有任何问题。
    【解决方案4】:

    不确定它是什么,但系统重启就可以了。问题解决了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-11
      • 1970-01-01
      • 2012-09-25
      • 1970-01-01
      • 1970-01-01
      • 2017-05-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多