5

I´m having trouble to access the rails console in production.

I used Capistranoto deploy the app to a VPS

If I cd to deploy@myapp:~/myapp/current$and run bundle exec rails cthere I always get the option list for creating new rails project, like rails new

I've also tried bundle exec rails console --productionand rails consoleetc all with the same outcome.

the thing is I must be able to access the console because I have to create an admin user for active admin

might be worth adding that I'm using Passenger/Capistrano and Nginx on Ubuntu 16

Does anyone know what is going on here? Am I doing something wrong?

*EDIT

After running RAILS_ENV=production bundle exec rails c I get this message

 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> 
DaudiHell
  • 808
  • 10
  • 32

4 Answers4

11

You are missing executable files of bin folder in Production after Capistrano deployment.

You need to remove bin from set :linked_dirs from your Capistrano deploy.rb in order to avoid symlinking it.

You can again try cap production deploy, it would take all the executable files from bin to Production.

Now, you can access the rails console using:

RAILS_ENV=production bundle exec rails c
dp7
  • 6,651
  • 1
  • 18
  • 37
1

If you are using Capistrano 3, you can include the rails:console option which will allow you to do this from your local machine to gain access to the console on the remote host:

bundle exec cap production rails:console

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

Jason Brodie
  • 330
  • 5
  • 13
  • If I use the `capistrano-rails-console' gem and `cd` into `deploy@myapp:~/myapp/current$` I get this error `(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 '' (See full trace by running task with --trace)` – DaudiHell Sep 29 '16 at 00:33
  • Are you missing dependencies for it? Are you using rbenv? I would have to see your gemfile and capfile to know what you are doing. – Jason Brodie Sep 29 '16 at 01:11
1

The Rails project is deployed in /deploy/your_project_name/current on the server by default. So, you can access it via SSH or ... and run bundle exec rails c to access the Rails console. It works for me!

Aboozar Rajabi
  • 1,683
  • 21
  • 26
  • This works, but only if you add `-e development` or `-e production` or whatever to specify the correct environment. `bundle exec rails c -e production` – Andrew Koster Dec 19 '19 at 09:12
-1

check if rvm and regarding gemset is suitable for the app

rvm gemset list 
rvm list

and then do

bin/rails rails c -e production
edrich13
  • 703
  • 6
  • 15