Покажите объекты ActiveRecord как таблица в./script/console

Как отобразить ActiveRecords как

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

?

Я видел его в railscasts.com/episodes/189-embedded-association и http://asciicasts.com/episodes/189-embedded-association

5
задан Vlad 17 December 2009 в 18:03
поделиться

1 ответ

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.

12
ответ дан 13 December 2019 в 05:36
поделиться
Другие вопросы по тегам:

Похожие вопросы: