How to display ActiveRecords like
>> Role.all
+----+-----------+-------------------------+-------------------------+
| id | name | created_at | updated_at |
+----+-----------+-------------------------+-------------------------+
| 1 | Admin | 2009-11-16 21:22:59 UTC | 2009-11-16 21:22:59 UTC |
| 2 | Moderator | 2009-11-16 21:23:06 UTC | 2009-11-16 21:23:06 UTC |
| 3 | Author | 2009-11-16 21:23:16 UTC | 2009-11-16 21:23:16 UTC |
+----+-----------+-------------------------+-------------------------+
3 rows in set
?
I saw it in railscasts.com/episodes/189-embedded-association and http://asciicasts.com/episodes/189-embedded-association
the answer is the "hirb" gem, you should just be able to do
sudo gem install hirb
then after calling script/console run
=> require 'hirb'
=> Hirb.enable
that will do it, hirb will intercept all of the ActiveRecord models being displayed and display in the table format. Also in that episode of Railscasts he uses this command
=> ActiveRecord::Base.logger = Logger.new(STDOUT)
that overrides the default logger for ActiveRecord and makes it output the sql commands it runs to the console, you MUST use this command as the very first command you use in the script/console irb session or it won't work. I use both of these all of the time when debugging or just making sure things are working okay. Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With