a rails console output looks like this:
User.all
=> [#<User id: 1, name: "Michael Hartl", email: "[email protected]",
created_at: "2011-12-05 00:57:46", updated_at: "2011-12-05 00:57:46">,
#<User id: 2, name: "A Nother", email: "[email protected]", created_at:
"2011-12-05 01:05:24", updated_at: "2011-12-05 01:05:24">]
I was wondering if there is command that can make it easier to read? for example there was a .pretty command in MongoDB console that was formatting the output a little more eye friendly. But not sure if there is something similar in Rails or not.
A bit more elegant shorthand:
y User.all
I've been using pp
. The pp stands for "pretty print." No Gem required.
On rails console try doing this:
pp User.all
You'll get each attributes and their value in the record display in a row instead a bundle of them if you simply do User.all.
Here's the documentation:
https://ruby-doc.org/stdlib-2.1.0/libdoc/pp/rdoc/PP.html
I am using Rails 5.1.3 and ruby 2.4.1p111 and it came already installed in my project. If this don't work, I imagine you have to do require 'pp'
.
I hope this helps.
If you don't want to use a gem, here's the low rent version:
puts User.all.to_yaml
Also you could use this incredible gem:
Awesome Print
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