How to get nice formatting in the Rails console

The y method is a handy way to get some pretty YAML output.

y ProductColor.all

Assuming you are in script/console

As jordanpg commented, this answer is outdated. For Rails 3.2+ you need to execute the following code before you can get the y method to work:

YAML::ENGINE.yamler="syck"

From ruby-docs

In older Ruby versions, ie. <= 1.9, Syck is still provided, however it
was completely removed with the release of Ruby 2.0.0.

For rails 4/ruby 2 you could use just

puts object.to_yaml

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)