public
Created

Logging mongoid in Sinatra

  • Download Gist
Rakefile
Ruby
1 2 3 4 5 6 7
desc "Irb with DB environment loaded"
task :console do
require './config/database'
require "irb"
ARGV.clear
IRB.start
end
database.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# encoding: utf-8
require 'mongoid'
# Connection.new takes host, port
host = 'localhost'
port = Mongo::Connection::DEFAULT_PORT
 
database_name = case ENV['RACK_ENV'].to_sym
when :development then 'varena'
when :production then 'varena'
when :test then 'varena_test'
end
 
Mongoid.configure do |config|
config.master = Mongo::Connection.new(host, port, logger: Logger.new($stdout)).db(database_name)
config.raise_not_found_error = false
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.