简体   繁体   English

如何查看我的gemfile中执行的所有查询以及类或方法?

[英]How I can see all the queries executed and classes or methods in my gemfile?

I´m newbie in RoR and I would like to know how I can do two things in Rails (both versions 2 and 3): 我是RoR的新手,我想知道如何在Rails中做两件事(版本2和3):

  1. How I can see all queries generated to database (save, update, find, etc.) in the console of the server? 如何在服务器的控制台中查看对数据库生成的所有查询(保存,更新,查找等)?

  2. How I can see all the classes and methods of gems included in my Gemfile? 如何查看Gemfile中包含的gem的所有类和方法?

    For example how I can see classes and methods of CanCan, Devise and so on. 例如,我如何查看CanCan,Devise等的类和方法。

     gem "devise" gem "cancan" gem "rolify" gem "sass-rails" 

And so on... 等等...

Sorry for my english and thank in advance!! 对不起,我的英语,谢谢!!

In your rails folder there will be a log sub-folder. 在rails文件夹中,将有一个日志子文件夹。 Depending on where your application is running and on your configurations you'll be able to see something similar to a development.log, staging.log or production.log file in that folder. 根据应用程序的运行位置和配置,您将能够在该文件夹中看到类似于development.log,staging.log或production.log文件的内容。

Also the .to_sql method can be used to show the sql. .to_sql方法也可以用于显示sql。 eg 例如

User.where(:id => 29).to_sql will yield the following: User.where(:id => 29).to_sql将产生以下结果:

"SELECT `users`.* FROM `users` WHERE `users`.`id` = 29"

For viewing gems. 用于查看宝石。 In terminal type bundle show devise this will return you a path. 在终端类型bundle show devise这将返回您的路径。 Go to that path. 去那条路。 All the necessary code will be present over there. 所有必要的代码将在那边显示。

/home/sohaib/.rvm/gems/ree-1.8.7-2011.03@moviepass/gems/devise-1.4.9

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM