Skip to content

Instantly share code, notes, and snippets.

@mindscratch
Created February 14, 2013 14:26
Show Gist options
  • Select an option

  • Save mindscratch/4953139 to your computer and use it in GitHub Desktop.

Select an option

Save mindscratch/4953139 to your computer and use it in GitHub Desktop.
Rack middleware to close Mongoid's connections to MongoDB. See https://github.com/mongoid/mongoid/issues/2369.
require 'mongoid'
class MongoidCloseConnections
def initialize(app)
@app = app
end
def call(env)
path = env['PATH_INFO'] || ''
begin
@app.call env
ensure
unless path.start_with?('/assets/')
Mongoid.default_session.disconnect
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment