首页 文章

如何在Heroku中运行rails控制台? Rails 5.1和postgresql

提问于
浏览
0

我一直在关注Rails应用程序的教程 . 本教程基于Rails 5,我使用的是Rails 5.1.2 . 一切都在当地很好用,并毫无问题地推送到heroku . 但是,当我通过运行以下命令在 生产环境 数据库上创建管理员用户时:

$ heroku run rails c

它返回以下错误:

/app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:292:in require':无法加载此类文件 - rack / handler / c(LoadError)来自/app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:292:inblock 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:inrequire'来自/app/vendor/bundle/ruby/2.4.0/gems/rack-2.0.3/lib/rack/handler.rb:74:in try_require'来自/ 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:服务器'来自/app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.3/lib/rails/commands/server/server_command.rb:68:in print_boot_information'来自/app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.3/lib/rails/commands/server/server_command.rb:38:in从'app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.3/lib/rails/commands/server/server_command.rb:131:in块中执行'来自/ app / vendor / bundle /ruby/2.4.0/gems/railties-5.1.3/lib/rails/commands/server/server_command.rb:126:in tap from 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:运行'来自/ app/vendor/bundle/ruby/2.4.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in invoke_command'来自/ app / vendor / bundle / ruby /2.4.0/gems/thor-0.20.0/lib/thor.rb:387:in dispatch'来自/app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.3/lib/rails/ command / base.rb:63:执行'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

这允许我更新 生产环境 数据库 . 虽然这有效,但我得到了我需要的东西 . 我想知道为什么原始命令不起作用 . 我到处寻找答案,但不能提出任何适合我的方法 . 我正在努力提高我的开发技能,并想了解为什么原始问题不起作用 .

我可以添加任何人需要查看的文件,但我甚至不知道哪些文件与此问题相关 .

1 回答

  • 0

    我的理解是 heroku run 命令由Heroku命令行界面(CLI)提供 . CLI不知道如何处理rails c命令 . 但是,运行 heroku run bash 将启动一个新的dyno并提供对Unix shell的访问,在那里你可以运行命令(即rails c),就像你是本地终端一样 . 有关详细信息,请参阅:https://devcenter.heroku.com/articles/how-heroku-works .

    编辑修复错误:CLI确实知道如何处理 rails c 命令

相关问题