部署到服务器

时间:2016-09-28 16:09:12

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

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

我使用Capistrano将应用部署到VPS

如果我转到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> 

4 个答案:

答案 0 :(得分:7)

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

您需要从Capistrano bin中删除set :linked_dirs中的deploy.rb,以避免将其符号化。

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

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

RAILS_ENV=production bundle exec rails c

答案 1 :(得分:1)

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

bundle exec cap production rails:console

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

答案 2 :(得分:0)

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

rvm gemset list 
rvm list

然后再做

bin/rails rails c -e production

答案 3 :(得分:0)

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