Quantcast
Channel: How to show SQL queries run in the Rails console? - Stack Overflow
Browsing latest articles
Browse All 10 View Live

Answer by Max Tkachenko for How to show SQL queries run in the Rails console?

For Rails v"6.1.7.3" the following combination worked for me:ActiveRecord::Base.logger = Logger.new(STDOUT)ActiveRecord::LogSubscriber.attach_to :active_record

View Article



Answer by Hosam Aly for How to show SQL queries run in the Rails console?

There are a few configuration parameters that control whether SQL queries are printed to the log.(This answer is based on Rails 6.0.)First, confirm that the logger is configured and its @logdev has a...

View Article

Answer by Noach Magedman for How to show SQL queries run in the Rails console?

I just wanted to give our production console the same behavior I’m used to on dev, where all SQL queries are reported to the console.Rails.logger.level = 03.0.3 :001 > Rails.logger.level = 0 =>...

View Article

Answer by kaleb4eg for How to show SQL queries run in the Rails console?

Starting from Rails 6 there is more convenient approach: simply add ActiveRecord::Base.verbose_query_logs = true in console and you will see all SQL calls and places where it was called. More info...

View Article

Answer by Huy Vo for How to show SQL queries run in the Rails console?

I prefer to set up logger level in config/application.rb:config.after_initialize do Rails.logger.level = (ENV['LOG_LEVEL'] || Logger::INFO).to_iendOn production my ENV['LOG_LEVEL'] will be set to the...

View Article


Image may be NSFW.
Clik here to view.

Answer by Aleksandar Pavić for How to show SQL queries run in the Rails console?

As from recently, you can use this:https://github.com/dejan/rails_panelIt consists of developer console panel add-on for chrome, and gem file which needs to be added to your application's Gemfile like...

View Article

Answer by Evgenia Karunus for How to show SQL queries run in the Rails console?

There is the .explain method in Rails 4.(.to_sql works too, but won't show includes)Category.includes(:products).explain=> EXPLAIN for: SELECT "categories".* FROM "categories" 0|0|0|SCAN TABLE...

View Article

Answer by Abhi for How to show SQL queries run in the Rails console?

In Rails 3+ you can use ActiveRecord::Relation’s to_sql method:User.where(:id => 3).to_sql#=> "SELECT \"users\".* FROM \"users\" WHERE \"users\".\"id\" = 3"

View Article


Answer by John Topley for How to show SQL queries run in the Rails console?

Rails 3+Enter this line in the console:ActiveRecord::Base.logger = Logger.new(STDOUT)Rails 2Enter this line in the console:ActiveRecord::Base.connection.instance_variable_set :@logger, Logger.new(STDOUT)

View Article


How to show SQL queries run in the Rails console?

When I run queries (e.g. MyModel.where(...) or record.associated_things) in the console, how can I see the actual database queries being run so I can gain more understanding of what is happening?

View Article
Browsing latest articles
Browse All 10 View Live




Latest Images