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

问题描述 投票:3回答:4

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

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

如果我cd到deploy@myapp:~/myapp/current$and运行bundle exec rails cthere我总是得到创建新rails项目的选项列表,如rails new

我也尝试过bundle exec rails console --productionand和rails consoleetc同样的结果。

问题是我必须能够访问控制台,因为我必须为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> 
ruby-on-rails ruby capistrano rails-console
4个回答
7
投票

您在Capistrano部署后缺少生产中的bin文件夹的可执行文件。

你需要从你的Capistrano bin中删除set :linked_dirs中的deploy.rb,以避免混淆它。

你可以再次尝试cap production deploy,它将从bin到生产的所有可执行文件。

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

RAILS_ENV=production bundle exec rails c

1
投票

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

bundle exec cap production rails:console

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


0
投票

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

rvm gemset list 
rvm list

然后呢

bin/rails rails c -e production

0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.