【问题标题】:accessing Rails Console after deploy to server部署到服务器后访问 Rails 控制台
【发布时间】:2017-02-06 17:39:45
【问题描述】:

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

我使用Capistrano将应用部署到 VPS

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

我也试过bundle exec rails console --productionrails 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> 

【问题讨论】:

  • 您有~/myapp/current/bin 文件夹吗?它是否包含rails
  • 是的,它在里面,但它似乎是空的......至少如果我ls进入它
  • 是的,它应该有可执行文件。检查你的 Github repo,它是否包含所有带有bin 的可执行文件。
  • 我查了一下,Github repo 里面全是文件
  • RAILS_ENV=production bundle exec rails c - 它显示的是哪个错误?

标签: ruby-on-rails ruby capistrano rails-console


【解决方案1】:

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

您需要从 Capistrano deploy.rb 中删除 set :linked_dirs 中的 bin 以避免符号链接。

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

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

RAILS_ENV=production bundle exec rails c

【讨论】:

  • 非常感谢,这对我很有帮助
  • RAILS_ENV=production bundle exec rails c 是我所需要的。
【解决方案2】:

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

bundle exec cap production rails:console

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

【讨论】:

  • 如果我使用capistrano-rails-console' gem and cd` 到deploy@myapp:~/myapp/current$ 我得到这个错误(Backtrace restricted to imported tasks) cap aborted! LoadError: cannot load such file -- capistrano/rbenv /home/deploy/hlinreykdal/releases/20160929002954/Capfile:25:in 'require' /home/deploy/hlinreykdal/releases/20160929002954/Capfile:25:in '<top (required)>' (See full trace by running task with --trace)
  • 您是否缺少它的依赖项?你用的是rbenv吗?我必须查看您的 gemfile 和 capfile 才能知道您在做什么。
【解决方案3】:

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

【讨论】:

  • 这有效,但前提是您添加 -e development-e production 或其他任何内容以指定正确的环境。 bundle exec rails c -e production
【解决方案4】:

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

rvm gemset list 
rvm list

然后做

bin/rails rails c -e production

【讨论】:

    猜你喜欢
    • 2014-05-26
    • 2020-06-03
    • 1970-01-01
    • 1970-01-01
    • 2019-12-11
    • 1970-01-01
    • 1970-01-01
    • 2012-06-02
    • 2023-03-21
    相关资源
    最近更新 更多