如何在 Heroku 中 运行 rails 控制台? Rails 5.1 和 postgresql
How can I run rails console in Heroku? Rails 5.1 and postgresql
我一直在关注 Rails 应用程序的教程。本教程基于 Rails 5,我使用的是 Rails 5.1.2。一切都在本地运行良好,并毫无问题地推送到 heroku。但是,当我通过 运行ning:
在生产数据库上创建管理员用户时
$ heroku run rails c
它returns以下错误:
/app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:292:in require': cannot load such file -- rack/handler/c (LoadError) from
/app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:292:in
block in require' from
/app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:258:in load_dependency' from
/app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:292:in
require' from
/app/vendor/bundle/ruby/2.4.0/gems/rack-2.0.3/lib/rack/handler.rb:74:in
try_require' from
/app/vendor/bundle/ruby/2.4.0/gems/rack-2.0.3/lib/rack/handler.rb:16:in
get' from
/app/vendor/bundle/ruby/2.4.0/gems/rack-2.0.3/lib/rack/server.rb:301:in
server' from
/app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.3/lib/rails/commands/server/server_command.rb:68:in
print_boot_information' from
/app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.3/lib/rails/commands/server/server_command.rb:38:in
start' from
/app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.3/lib/rails/commands/server/server_command.rb:131:in
block in perform' from
/app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.3/lib/rails/commands/server/server_command.rb:126:in
tap' from
/app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.3/lib/rails/commands/server/server_command.rb:126:in
perform' from
/app/vendor/bundle/ruby/2.4.0/gems/thor-0.20.0/lib/thor/command.rb:27:in
run' from
/app/vendor/bundle/ruby/2.4.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in
invoke_command' from
/app/vendor/bundle/ruby/2.4.0/gems/thor-0.20.0/lib/thor.rb:387:in
dispatch' from
/app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.3/lib/rails/command/base.rb:63:in
perform' from
/app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.3/lib/rails/command.rb:44:in
invoke' from
/app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.3/lib/rails/commands.rb:16:in
' from bin/rails:9:in require' from bin/rails:9:in
'`
为了解决这个问题,我可以 运行:
$ heroku run bash
$ rails c
这让我可以更新生产数据库。虽然这有效并且让我得到了我需要的东西。我想知道为什么原来的命令不起作用。我到处寻找答案,但找不到任何适用于我的答案。我正在努力提高我的开发技能,并想了解为什么原来的问题不起作用。
我可以添加任何人需要查看的文件,但我什至不知道哪些文件与此问题相关。
我的理解是 heroku run
命令是由 Heroku 命令行界面 (CLI) 提供的。 CLI 不知道如何处理 rails c
命令。但是,运行ning heroku run bash
将启动一个新的 dyno 并提供对 Unix shell 的访问,您可以在其中 运行 命令(即 rails c)就像你是本地终端。有关详细信息,请参阅:https://devcenter.heroku.com/articles/how-heroku-works。
已编辑以修复错误:CLI 确实知道如何处理 rails c
命令
如果您有多个应用程序,您可以指定应用程序的名称:
heroku run rails c -a APP_NAME
我一直在关注 Rails 应用程序的教程。本教程基于 Rails 5,我使用的是 Rails 5.1.2。一切都在本地运行良好,并毫无问题地推送到 heroku。但是,当我通过 运行ning:
在生产数据库上创建管理员用户时$ heroku run rails c
它returns以下错误:
/app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:292:in
require': cannot load such file -- rack/handler/c (LoadError) from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:292:in
block in require' from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:258:inload_dependency' from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:292:in
require' from /app/vendor/bundle/ruby/2.4.0/gems/rack-2.0.3/lib/rack/handler.rb:74:intry_require' from /app/vendor/bundle/ruby/2.4.0/gems/rack-2.0.3/lib/rack/handler.rb:16:in
get' from /app/vendor/bundle/ruby/2.4.0/gems/rack-2.0.3/lib/rack/server.rb:301:inserver' from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.3/lib/rails/commands/server/server_command.rb:68:in
print_boot_information' from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.3/lib/rails/commands/server/server_command.rb:38:instart' from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.3/lib/rails/commands/server/server_command.rb:131:in
block in perform' from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.3/lib/rails/commands/server/server_command.rb:126:intap' from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.3/lib/rails/commands/server/server_command.rb:126:in
perform' from /app/vendor/bundle/ruby/2.4.0/gems/thor-0.20.0/lib/thor/command.rb:27:inrun' from /app/vendor/bundle/ruby/2.4.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in
invoke_command' from /app/vendor/bundle/ruby/2.4.0/gems/thor-0.20.0/lib/thor.rb:387:indispatch' from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.3/lib/rails/command/base.rb:63:in
perform' from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.3/lib/rails/command.rb:44:ininvoke' from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.3/lib/rails/commands.rb:16:in
' from bin/rails:9:inrequire' from bin/rails:9:in
'`
为了解决这个问题,我可以 运行:
$ heroku run bash
$ rails c
这让我可以更新生产数据库。虽然这有效并且让我得到了我需要的东西。我想知道为什么原来的命令不起作用。我到处寻找答案,但找不到任何适用于我的答案。我正在努力提高我的开发技能,并想了解为什么原来的问题不起作用。
我可以添加任何人需要查看的文件,但我什至不知道哪些文件与此问题相关。
我的理解是 heroku run
命令是由 Heroku 命令行界面 (CLI) 提供的。 CLI 不知道如何处理 。但是,运行ning rails c
命令heroku run bash
将启动一个新的 dyno 并提供对 Unix shell 的访问,您可以在其中 运行 命令(即 rails c)就像你是本地终端。有关详细信息,请参阅:https://devcenter.heroku.com/articles/how-heroku-works。
已编辑以修复错误:CLI 确实知道如何处理 rails c
命令
如果您有多个应用程序,您可以指定应用程序的名称:
heroku run rails c -a APP_NAME