Friday, November 2, 2012

Is there a way through which I see which mysql queries are fired from ActiveRecord in rails console?

http://stackoverflow.com/questions/4667316/how-to-see-mysql-queries-in-rails-console

Yes, this can be achieved through redirecting rails log to standard output.

Write these at your console prompt:

ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.connection_pool.clear_reloadable_connections!
Furthermore, you can put these lines in ~/.irbrc file, so that each time you don't need to manually write these 2 lines:

require 'rubygems'

if ENV.include?('RAILS_ENV') && ENV["RAILS_ENV"] == 'development'
    ActiveRecord::Base.logger = Logger.new(STDOUT)
    ActiveRecord::Base.connection_pool.clear_reloadable_connections!
end

1 comment:

  1. In seven different states, could be} some type of pending legislation. Charles is a nationally recognized capital markets specialist and educator with over 30 years of expertise developing in-depth coaching programs for burgeoning financial professionals. Charles has taught at quantity of|numerous|a selection of} institutions together with Goldman Sachs, Morgan Stanley, Societe Generale, 토토사이트 tons of|and a lot of} more. Sign up for a Club Sycuan card today and you’ll mechanically become a Gold cardholder.

    ReplyDelete