部署到服务器后访问 Rails 控制台

accessing Rails Console after deploy to server

我在生产环境中无法访问 rails 控制台。

我使用 Capistrano 将应用程序部署到 VPS

如果我 cd 到 deploy@myapp:~/myapp/current$ 和 运行 bundle exec rails c,我总能得到用于创建新 rails 项目的选项列表,例如 rails new

我也试过 bundle exec rails console --productionrails console 等等,结果都一样。

问题是我必须能够访问控制台,因为我必须为 active admin

创建一个管理员用户

可能值得补充一点,我在 Ubuntu 16

上使用 Passenger/Capistrano 和 Nginx

有人知道这里发生了什么吗?我做错了什么吗?

*编辑

在运行宁RAILS_ENV=production bundle exec rails c之后我收到这条消息

 Looks like your app's ./bin/rails is a stub that was generated by Bundler.

 In Rails 4, your app's bin/ directory contains executables that are  versioned
 like any other source code, rather than stubs that are generated on demand.

  Here's how to upgrade:

  bundle config --delete bin    # Turn off Bundler's stub generator
   rake rails:update:bin         # Use the new Rails 4 executables
  git add bin                   # Add bin/ to source control

   You may need to remove bin/ from your .gitignore as well.

  When you install a gem whose executable you want to use in your app,
  generate it and add it to source control:

  bundle binstubs some-gem-name
  git add bin/new-executable

  Loading production environment (Rails 4.2.5)
  irb(main):001:0> 

Capistrano 部署后 Production 中缺少 bin 文件夹的可执行文件。

您需要从 Capistrano deploy.rbset :linked_dirs 中删除 bin 以避免对其进行符号链接。

您可以再次尝试 cap production deploy,它将把所有可执行文件从 bin 带到生产环境。

现在,您可以使用以下方式访问 rails 控制台:

RAILS_ENV=production bundle exec rails c

如果您使用的是 Capistrano 3,您可以包含 rails:console 选项,这将允许您从本地计算机执行此操作以访问远程主机上的控制台:

bundle exec cap production rails:console

https://rubygems.org/gems/capistrano-rails-console

检查 rvm 和 gemset 是否适合该应用程序

rvm gemset list 
rvm list

然后

bin/rails rails c -e production

Rails项目默认部署在服务器/deploy/your_project_name/current中。因此,您可以通过 SSH 或 ... 和 运行 bundle exec rails c 访问它以访问 Rails 控制台。对我有用!