How to fix 'spring is not part of the bundle' when trying to run rails console in production

642 Views Asked by At

I'd like to be able to run rails console on an app installed with Capistrano(3).

So, I added gem 'capistrano-rails-console', require: false to the gemfile

the following to the deploy.rb

server 'ip', port: 2, user: 'user', roles: [:web, :app, :db], primary: true

and the following to the Capfile require 'capistrano/rails/console'

The problem is that cap production rails:console leads to the following error

00:00 rails:console
      01 $HOME/.rbenv/bin/rbenv exec bundle exec rails console -e production
Traceback (most recent call last):
    3: from bin/rails:7:in `<main>'
    2: from bin/rails:7:in `load'
    1: from /_some_path_/releases/20210808154555/bin/spring:14:in `<top (required)>'
/home/_user_/.rbenv/versions/2.7.2/lib/ruby/2.7.0/bundler/rubygems_integration.rb:346:in `block (2 levels) in replace_gem': spring is not part of the bundle. Add it to your Gemfile. (Gem::LoadError)

How can I fix this?

2

There are 2 best solutions below

3
B Seven On BEST ANSWER

You probably need to add Spring to the Gemfile.

Can you show your Gemfile?

If you have something like

group :development do
  gem 'spring'

You can promote it above the block.

0
jibai31 On

I had the same problem after a migration to Rails 6.1. My bin/rails looked like this and it caused the same error you had:

#!/usr/bin/env ruby
load File.expand_path('spring', __dir__)
APP_PATH = File.expand_path('../config/application', __dir__)
require_relative '../config/boot'
require 'rails/commands'

I had to modify it like that (wrapping the first line in a rescue block):

#!/usr/bin/env ruby
begin
  load File.expand_path('spring', __dir__)
rescue LoadError => e
  raise unless e.message.include?('spring')
end
APP_PATH = File.expand_path('../config/application', __dir__)
require_relative '../config/boot'
require 'rails/commands'