Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load problem when used outside of Rails (No connection pool for PaperTrail::VersionAssociation) #775

Closed
codingluke opened this issue Apr 13, 2016 · 1 comment

Comments

@codingluke
Copy link

Hello, we are using paper_trail in a non Rails Project, just together with ActiveRecord. PaperTrail is in this situation not dynamically loaded, so we have to load it manually with require 'paper_trail' before defining our models. So far so good.

On loading, the config.rb is doing a database lookup to check whether the table version_associations is available or not (https://github.com/airblade/paper_trail/blob/4.1-stable/lib/paper_trail/config.rb#L32). As in our case the database connection is done later, we encounter the error No connection pool for PaperTrail::VersionAssociation (ActiveRecord::ConnectionNotEstablished)

We could fix this with the simple Monkey Patch below. As we are not using the track-association-feature, we just overwrite the PaperTrail::Config.track_associations? method before loading paper_trail. In my opinion, it would be better to explicit enable/disable the track_association feature instead of magically enable it when the table exists. This would fix the loading problem in a non rails environment.

require 'paper_trail/config'
module PaperTrail
    class Config
        def track_associations?
            false
        end
    end
end
require 'paper_trail'
@jaredbeck
Copy link
Member

Hi Lukas. I think this is basically a duplicate of #740

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants