Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 539
kirqe Avatar asked Sep 11 '25 01:09

kirqe


1 Answers

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'
like image 66
jibai31 Avatar answered Sep 12 '25 15:09

jibai31