Search code examples
ruby-on-railsruby-on-rails-3gemfilerails-console

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):

  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?

    For example how I can see classes and methods of CanCan, Devise and so on.

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

And so on...

Sorry for my english and thank in advance!!


Solution

  • In your rails folder there will be a log sub-folder. 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.

    Also the .to_sql method can be used to show the sql. e.g.

    User.where(:id => 29).to_sql will yield the following:

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

    For viewing gems. In terminal type bundle show devise this will return you a path. 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