0

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!!

Julieta
  • 81
  • 2
  • 10

1 Answers1

0

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

sohaibbbhatti
  • 2,672
  • 22
  • 21
  • I tried it but (undefined method `to_sql' for # – Julieta Nov 17 '12 at 16:27
  • That is because .find will return an object(Ticket in this case) and update_attribute will return a true or false. to_sql can be used when an ActiveRecord::Relation is being returned. – sohaibbbhatti Nov 17 '12 at 16:46
  • Thank!!.. But how i can see the query on the methods save and update_attributes?? That is it possible?? Thank again – Julieta Nov 17 '12 at 17:06