为什么 Pry 不能在 Heroku 的控制台中运行?
我的目标是在本地和临时服务器上使用 Pry 作为 Rails 应用程序的控制台。但我无法让它在 Heroku 上运行。
我正在关注 这些 让 Heroku 使用 Pry 作为我的 Rails 应用程序的控制台的说明。当我运行 heroku run console pry
时,我的控制台会打印 Running console pry Attached to Terminal... up, run.1
然后退出。当我运行 heroku console pry
时,它只是显示 main
然后退出。
对我做错了什么有什么想法吗?
这是我到目前为止所做的:
在我的Gemfile中我添加了以下行:
宝石“撬”
gem 'pry-rails'
我创建了一个名为 pry 的文件,其中包含:
#!/usr/bin/env ruby
需要“撬”
pry
我将以下内容添加到config/environments中的所有文件中:
silence_warnings 执行
开始
需要“撬”
IRB = 撬
救援LoadError
结束
end
运行
bundle install
- 运行
git Push staging master
My goal is to use Pry as the console for my Rails app, both locally and on my staging server. But I can't get it to work on Heroku.
I'm following these instructions to get Heroku to use Pry as the console for my Rails app. When I run heroku run console pry
, my console prints Running console pry attached to terminal... up, run.1
and then exits. When I run heroku console pry
it just says main
and then exits.
Any ideas on what I'm doing wrong?
Here's what I've done so far:
In my Gemfile I've added the lines:
gem 'pry'
gem 'pry-rails'
I've created a file called pry which contains:
#!/usr/bin/env ruby
require 'pry'
pry
I added the following to all the files in config/environments:
silence_warnings do
begin
require 'pry'
IRB = Pry
rescue LoadError
end
end
run
bundle install
- run
git push staging master
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我是为 Heroku 和 Pry 开发该方法的人,但你提出了一个我没有想到的有趣案例,因为我主要使用 Sinatra 和 EM 进行部署并构建自己的助手等。无论哪种方式:
要在拥有 Rails 应用程序的同时将 Pry 与 Heroku 一起使用,您只需将 pry-rails 和 pry 添加到您的 gemfile(作为普通 Gem),然后
bundle install
,然后git [ commit|push]
并在 Cedar 堆栈上运行heroku run console
。您在调整配置/环境时所做的第 3 步没有也不应该完成,因此如果可以的话请恢复该更改。完成此操作并从应用程序的根目录中删除 pry 脚本后(您不一定需要执行后者),Pry 将正确加载您的 Rails。I am the one who developed the method for Heroku and Pry but you brought up an interesting case that I didn't think about since I mostly deploy with Sinatra and EM and build my own helpers and such. Either way:
To use Pry with Heroku while having a Rails app you just need to add pry-rails and pry to your gemfile (as a normal Gem) and then
bundle install
and thengit [commit|push]
and runheroku run console
on Cedar stack. Step 3 of what you did where you adjusted config/environments does not and should not be done so please revert that change if you can. After you do that and remove the pry script from the root of your app (well you don't necessarily need to do the latter) Pry will load with your Rails properly.我刚刚使用了 https 上的说明://github.com/pry/pry/wiki/Setting-up-Rails-or-Heroku-to-use-Pry 进行设置,pry 文件位于项目的根目录中。提交并推送到 Heroku - 我正在使用 Cedar 堆栈。
将控制台会话影响到
heroku run console pry
- 我确实发现我确实需要执行pry
才能进入 pry 提示符,但它随后按照我的方式工作预计。更新:为了清楚起见,我将 pry 添加到 Gemfile 中并按照说明创建了 pry 文件。您的问题是您将 gemfile 中的 pry 锁定到开发/测试 - 您是否在这些环境中的 Heroku 上运行您的应用程序?那么为什么你会得到未定义的方法呢?
I've just used the instructions at https://github.com/pry/pry/wiki/Setting-up-Rails-or-Heroku-to-use-Pry to set it up, pry file goes in the root of your project. Commit and push to Heroku - I'm using the Cedar stack.
Effect a console session to
heroku run console pry
- I did find that I did then need to executepry
to be dropped into a pry prompt but it then worked as I'd expect.UPDATE: Just to be clear, I added pry to Gemfile and created the pry file as instructed. Is your problem that you are locking pry in your gemfile to dev/test - are you running your apps on Heroku in those environments? Hence why you're getting undefined methods?
您可能必须将其列出在您的捆绑程序 Gemfile 中。
You probably have to list it in your bundler Gemfile.