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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleHow 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
More Pages to Explore .....