Skip to content

Instantly share code, notes, and snippets.

@rondy
Last active December 27, 2015 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rondy/7372736 to your computer and use it in GitHub Desktop.
Save rondy/7372736 to your computer and use it in GitHub Desktop.
# This initializer adds a method, show_mongo, when running a rails console. When active, all
# moped commands (moped is mongoid's mongodb driver) will be logged inline in the console output.
# If called again, logging will be restored to normal (written to log files, not shown inline).
# Usage:
# > show_mongo
if defined?(Rails::Console)
def show_mongo
if Moped.logger == Rails.logger
Moped.logger = Logger.new($stdout)
true
else
Moped.logger = Rails.logger
false
end
end
alias :show_moped :show_mongo
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment