如何在关闭pry的情况下启动rails控制台?

时间:2022-02-16 20:43:45

Sometimes I have reason to want to start the rails console as an irb repl rather than pry (as awesome as pry is). It will default to pry because pry has in the Gemfile. Hows is that done nowadays?

有时我有理由想要将rails控制台作为irb repl而不是pry启动(就像pry一样棒)。它将默认为pry,因为pry在Gemfile中。如何做到现在这样做?

I think there used to be a --irb option when running rails console but that seems to be gone now. I get a deprecation error message when I try it.

我认为在运行rails console时曾经有过--irb选项,但现在似乎已经消失了。我尝试时收到了弃用错误消息。

More details

If I just run "rails console" it takes me to pry.

如果我只是运行“rails console”,它就会让我撬开。

If I run "rails console -irb=irb":

如果我运行“rails console -irb = irb”:

$ rails c -irb=irb                                                                                                                                                                         
--irb option is no longer supported. Invoke `/your/choice/of/ruby script/rails console` instead

Relevent lines from my Gemfile:

我的Gemfile中的相关行:

gem 'rails', '3.2.18'
gem 'pry-rails'
gem 'pry-plus'

4 个解决方案

#1


14  

Launching pry when calling rails console or rails c is set up by the pry-rails gem. If you look in the pry-rails issues there is one that describes a solution.

调用rails console或rails c时启动pry是由pry-rails gem设置的。如果您查看pry-rails问题,可以使用一个描述解决方案的问题。

Define the environment variable DISABLE_PRY_RAILS as 1.

将环境变量DISABLE_PRY_RAILS定义为1。

So you can call rails console without pry with:

所以你可以调用rails console而不用pry:

DISABLE_PRY_RAILS=1 rails c

#2


5  

Works in Rails 4: In your application.rb, inside your Application class, drop this puppy in.

在Rails 4中工作:在你的application.rb中,在你的Application类中,放下这只小狗。

# Use the IRB console instead of the Pry one
console do
  require 'irb'
  config.console = IRB
end

I couldn't take the Pry console anymore. It kept putting my cursor in odd places at unpredictable times. I can't even describe it but if you know what I'm talking about and know the solution, please let me know.

我不能再拿Pry控制台了。它在不可预测的时间将光标放在奇怪的地方。我甚至无法描述它,但如果你知道我在说什么并知道解决方案,请告诉我。

#3


1  

For the benefit of anyone who runs into the same problem, this is my (crappy) workaround.

为了遇到同样问题的人的利益,这是我的(糟糕的)解决方法。

I wrapped the pry gems in Gemfile with this:

我用Gemfile包装了撬宝石:

...
unless ENV['NOPRY']
  gem 'pry-rails'
  gem 'pry-plus'
end
...

Then run this from the unix terminal:

然后从unix终端运行:

NOPRY=true bundle install
NOPRY=true rails console

Not pretty, but gets the job done...

不漂亮,但完成工作......

#4


0  

Inspired by the answers above, I added the following to the class definition in application.rb so that Pry is toggleable from the console:

受上面答案的启发,我在application.rb中的类定义中添加了以下内容,以便可以从控制台切换Pry:

console do
  if ENV['IRB']
    require 'irb'
    config.console = IRB
  end
end

You can then run rails c to get a Pry console, and IRB=true rails c to get an IRB console. This is easily modified if you want the inverse. Works in Rails 4 and 5.

然后,您可以运行rails c以获取Pry控制台,并使用IRB = true rails c来获取IRB控制台。如果您想要反转,这很容易修改。适用于Rails 4和5。

#1


14  

Launching pry when calling rails console or rails c is set up by the pry-rails gem. If you look in the pry-rails issues there is one that describes a solution.

调用rails console或rails c时启动pry是由pry-rails gem设置的。如果您查看pry-rails问题,可以使用一个描述解决方案的问题。

Define the environment variable DISABLE_PRY_RAILS as 1.

将环境变量DISABLE_PRY_RAILS定义为1。

So you can call rails console without pry with:

所以你可以调用rails console而不用pry:

DISABLE_PRY_RAILS=1 rails c

#2


5  

Works in Rails 4: In your application.rb, inside your Application class, drop this puppy in.

在Rails 4中工作:在你的application.rb中,在你的Application类中,放下这只小狗。

# Use the IRB console instead of the Pry one
console do
  require 'irb'
  config.console = IRB
end

I couldn't take the Pry console anymore. It kept putting my cursor in odd places at unpredictable times. I can't even describe it but if you know what I'm talking about and know the solution, please let me know.

我不能再拿Pry控制台了。它在不可预测的时间将光标放在奇怪的地方。我甚至无法描述它,但如果你知道我在说什么并知道解决方案,请告诉我。

#3


1  

For the benefit of anyone who runs into the same problem, this is my (crappy) workaround.

为了遇到同样问题的人的利益,这是我的(糟糕的)解决方法。

I wrapped the pry gems in Gemfile with this:

我用Gemfile包装了撬宝石:

...
unless ENV['NOPRY']
  gem 'pry-rails'
  gem 'pry-plus'
end
...

Then run this from the unix terminal:

然后从unix终端运行:

NOPRY=true bundle install
NOPRY=true rails console

Not pretty, but gets the job done...

不漂亮,但完成工作......

#4


0  

Inspired by the answers above, I added the following to the class definition in application.rb so that Pry is toggleable from the console:

受上面答案的启发,我在application.rb中的类定义中添加了以下内容,以便可以从控制台切换Pry:

console do
  if ENV['IRB']
    require 'irb'
    config.console = IRB
  end
end

You can then run rails c to get a Pry console, and IRB=true rails c to get an IRB console. This is easily modified if you want the inverse. Works in Rails 4 and 5.

然后,您可以运行rails c以获取Pry控制台,并使用IRB = true rails c来获取IRB控制台。如果您想要反转,这很容易修改。适用于Rails 4和5。