Ruby - Activerecord::Connectionnotestablished

Ruby - ActiveRecord::ConnectionNotEstablished

I had the same problem, I started the sample-app from scratch and used this gemfile:

source 'http://rubygems.org'

gem 'rails', '3.1.1'

gem 'sqlite3'

group :development do
gem 'rspec-rails', '2.6.1'
end

group :test do
gem 'rspec-rails', '2.6.1'
gem 'webrat', '0.7.1'
end

group :assets do
gem 'sass-rails', '~> 3.1.4'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

This solved the problem for me :)

ActiveRecord::ConnectionNotEstablished randomly occured in deployed instance after migrate from Rails 5.2 to Rails 6.0

Make sure your application is not calling ActiveRecord::Base.establish_connection manually for example, inside a health check route. Calling establish_connection is not required as ActiveRecord establishes its own connection automatically in Rails.

When you call this method yourself, it destroys the old database connection pool and recreates another one.

[help]ActiveRecord::ConnectionNotEstablished

Try to set host: localhost and remove socket from database.yml

ActiveRecord::ConnectionNotEstablished (No connection pool with 'primary' found.) when rendering results

I was able to solve the issue by adding "each_serializer: nil" to render. It seems like Rails doesn't have a connection pool to 'primary' because this end point just connects to the :trmain db, but render for some reason wants to find a ActiveRecord serializer from primary.

def show
appuser_id = params[:id]
user_details = Appuser.find_user_details(appuser_id: appuser_id)
render json: user_details, status: 200, each_serializer: nil
end


Related Topics



Leave a reply



Submit