ruby-on-rails - rails : How to find out what query is being run in SQL when a page loads?

标签 ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.2

我想知道当用户与网站上的不同页面交互时正在运行哪些查询?我还想知道每个查询花了多长时间。我如何以及在哪里可以看到它?

最佳答案

每个 rails 应用程序中都有一个日志文件夹,其中包含您运行应用程序的每个环境的 .log 文件。您将看到这些类型其中的统计数据:

Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2012-11-29 11:09:47 -0400
Served asset /jquery.js - 200 OK (3ms)

Started GET "/users/auth/google/callback?_method=post&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.mode=id_res&openid.op_endpoint=https%3A%2F%2Fwww.google.com%2Faccounts%2Fo8%2Fud&openid.response_nonce=2012-10-26T19%3A29%3A52ZkvQlFeFr5Rk78g&openid.return_to=http%3A%2F%2Flocalhost%3A3000%2Fusers%2Fauth%2Fgoogle%2Fcallback%3F_method%3Dpost&openid.assoc_handle=AMlYA9VjNZ-QIIMe5bhvtPLBsAdm5xMltOa7MEwUoW4Opx9tXd_khhcS&openid.signed=op_endpoint%2Cclaimed_id%2Cidentity%2Creturn_to%2Cresponse_nonce%2Cassoc_handle%2Cns.ext1%2Cext1.mode%2Cext1.type.ext2%2Cext1.value.ext2%2Cext1.type.ext0%2Cext1.value.ext0%2Cext1.type.ext3%2Cext1.value.ext3&openid.sig=ehFAJ1m8nPces8%2Bj6Ud%2FicpuohY%3D&openid.identity=https%3A%2F%2Fwww.google.com%2Faccounts%2Fo8%2Fid%3Fid%3DAItOawljL9RKBE7iUQHk94UhJQ-4sDOTawUfpNc&openid.claimed_id=https%3A%2F%2Fwww.google.com%2Faccounts%2Fo8%2Fid%3Fid%3DAItOawljL9RKBE7iUQHk94UhJQ-4sDOTawUfpNc&openid.ns.ext1=http%3A%2F%2Fopenid.net%2Fsrv%2Fax%2F1.0&openid.ext1.mode=fetch_response&openid.ext1.type.ext2=http%3A%2F%2Faxschema.org%2FnamePerson%2Ffirst&openid.ext1.value.ext2=Fernando&openid.ext1.type.ext0=http%3A%2F%2Faxschema.org%2Fcontact%2Femail&openid.ext1.value.ext0=fernando%40findhorsesforsale.net&openid.ext1.type.ext3=http%3A%2F%2Faxschema.org%2FnamePerson%2Flast&openid.ext1.value.ext3=Mendez" for 127.0.0.1 at 2012-10-26 15:29:52 -0400

Started GET "/run_dates/current_pdf_generation_status.js?pdf_generation_id=e3ef90b05844012f4fc2723c91dfe57c&_=1332637701414" for 127.0.0.1 at 2012-03-24 21:08:29 -0400
Processing by RunDatesController#current_pdf_generation_status as JS
  Parameters: {"pdf_generation_id"=>"e3ef90b05844012f4fc2723c91dfe57c", "_"=>"1332637701414"}
  User Load (0.2ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
  RunDate Load (0.1ms)  SELECT "run_dates".* FROM "run_dates" WHERE (pdf_generation_id = 'e3ef90b05844012f4fc2723c91dfe57c') LIMIT 1
  Rendered run_dates/current_pdf_generation_status.js.erb (0.1ms)
Completed 200 OK in 4ms (Views: 2.0ms | ActiveRecord: 0.3ms)
.....

关于ruby-on-rails - rails : How to find out what query is being run in SQL when a page loads?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15550067/

相关文章:

ruby-on-rails-3 - 无法在轨道上的可安装引擎中加载模型

ruby-on-rails - Rails 3.2 以前在 words 方法中返回 html 内容

ruby-on-rails - 用散列对数组求和

ruby - mongoid 会自动索引字段 _id 吗?

ruby-on-rails - 用于谷歌地图集成的 Ruby on Rails gem

ruby-on-rails - Rails 3 If 语句,,, IF XXX 至少等于一个 (Var1, Var2, Var3)

sql - 为什么我的用户表没有列错误?

ruby-on-rails - 在 Ruby 中打开并读取 Google Drive 中的文件

ruby-on-rails - 如何在 Rails 中获取 URL 参数?

mysql - MySQL 的 Rails 迁移整理