- use Pry command: in rails console:
> pry
you will redirected to pry console:
pry(main)
- use Yaml command: in rails console:
> y User.first.attributes
or
> puts User.last.attributes.to_yaml
- use Awesome print gem: add gem 'awesome_print' to Gemfile and in rails console:
> require 'awesome_print'
> ap User.first
- use Hirb gem: (show result as Mysql result) add gem 'hirb' to Gemfile and in rails console:
> require 'hirb'
> Hirb.enable
> Movie.select("title, year, genre,director").first
>
+----+--------+------+-------------------+------------+
| id | title | year | genre | director |
+----+--------+------+-------------------+------------+
| | Batman | 1989 | Action, Adventure | Tim Burton |
+----+--------+------+-------------------+------------+
- Irbtools (like Hirb): Add gem 'irbtools' to Gemfile and in rails console:
> require 'irbtools'
> Movie.select("title, year, genre,director").first
>
┌────┬────────┬──────┬───────────────────┬────────────┐
│ id │ title │ year │ genre │ director │
├────┼────────┼──────┼───────────────────┼────────────┤
│ ╎ Batman ╎ 1989 ╎ Action, Adventure ╎ Tim Burton │
└────┴────────┴──────┴───────────────────┴────────────┘
- Table print (like Hirb): Add gem 'table_print' to Gemfile and in rails console:
> tp Movie.first
> tp Movie.first, "title", "year", "genre", "director"
TITLE | YEAR | GENRE | DIRECTOR
-------|------|-------------------|-----------
Batman | 1989 | Action, Adventure | Tim Burton