I'm trying to create a little app with Sinatra and ActiveRecord (3.2.3).
This is how my main file looks like:
require "sinatra"
require "sinatra/reloader"
require "active_record"
...
ActiveRecord::Base.establish_connection(
adapter: 'sqlite3',
database: 'db.sqlite3',
host: 'localhost',
)
class Post < ActiveRecord::Base
...
end
get('/') { ... }
get('/posts') { ... }
...
It works, but sometimes I get a warning in console:
DEPRECATION WARNING: Database connections will not be closed
automatically, please close your database connection at the end of the
thread by calling close
on your connection. For example:
ActiveRecord::Base.connection.close'
When warning occurs it's takes a long time before page refreshes.
I don't understand where I should close connection. I've tried to put ActiveRecord::Base.connection.close
at the bottom of file, but it doesn't help.
update:
I forgot to mention that I also use sinatra/reloader plugin from sinatra-contrib gem to look at effect without restarting server.
require "sinatra/reloader"
If I comment it out then the problem disappears. But anyway, I'm wondering how to get rid of the problem without disabling reloader.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…