ActiveRecord :: ConnectionNotEstablished error (downloaded download?)

I am developing OSX and deploying to Linux. My environment:

Development:

OSX Lion Ruby 1.9.2p180 ActiveRecord 3.0.9 PostgreSQL 9.0 

Test:

 Ubuntu Server 11.04 Ruby 1.9.2p290 ActiveRecord 3.1.1 PostgreSQL 9.1 

The following code snippets work on OSX, but not Linux:

 ei_doc_type = TaxDoc::Model::DocType.find_by_doc_type("EI") doc_version = ei_doc_type.doc_versions.find_by_doc_version(edoc.version) customer.electronic_invoices.create(....) 

and

 ei_doc_type = TaxDoc::Model::DocType.find_by_doc_type("EI") ei_doc_type.doc_versions.each { |doc_version| @mappings[doc_version.doc_version] = Hash.new doc_version.mappings.each { |mapping| @mappings[doc_version.doc_version][mapping.column_name] = mapping.xml_element } } 

When I try to run any of these code snippets on Linux, I get the following error:

 .../connection_pool.rb:409: in `retrieve_connection': ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished) 

I changed the code and it works on Linux:

 ei_doc_type = TaxDoc::Model::DocType.find_by_doc_type("EI") doc_versions = TaxDoc::Model::DocVersion.where(:doc_type_id => ei_doc_type.id, :doc_version => edoc.version) doc_version = doc_version.first customer.electronic_invoices.create(....) 

and

 ei_doc_type = TaxDoc::Model::DocType.includes(:doc_versions => :mappings).find_by_doc_type("EI") ei_doc_type.doc_versions.each { |doc_version| @mappings[doc_version.doc_version] = Hash.new doc_version.mappings.each { |mapping| @mappings[doc_version.doc_version][mapping.column_name] = mapping.xml_element } } 

It seems that impatient loading for first-order associations does not work in the test environment and in the first example. Even if I use "includes", it does not work.

Is there a difference between ActiveRecord or PostgreSQL versions that might be causing this?

These are my models:

 class DocType < EDocsDatabase has_many :doc_versions, :dependent => :destroy has_many :mappings, :through => :doc_versions has_many :service_types end class DocVersion < EDocsDatabase belongs_to :doc_type has_many :mappings, :dependent => :destroy end class Mapping < EDocsDatabase belongs_to :doc_version end 
+6
source share
1 answer

In what context are you using this code?

The reason is that ActiveRecord currently requires some management of the connection pool if you run your code in a response loop (for example, on the server). Rails addresses this using middleware that manages AR connections for you outside of your main application responder. However, if you do not have this type of wrapper, you may have other β€œapproaches” to your connection pool, especially when using streaming servers.

0
source

Source: https://habr.com/ru/post/899232/


All Articles