watching activerecord

# This greatly helps learning what ActiveRecord does!

# All credits go to Jamis Buck at
# http://weblog.jamisbuck.org/2007/1/31/more-on-watching-activerecord

# environment.rb
def log_to(stream)
  ActiveRecord::Base.logger = Logger.new(stream)
  ActiveRecord::Base.clear_active_connections!
end

# in irb or script/console or environment.rb
log_to(STDOUT)

# or create new streams
buffer = StringIO.new
log_to(buffer)
puts buffer.string


Leave a Reply

Formatting: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>