Leahcim
Leahcim

Reputation: 41999

Rails: How to display results with Yaml in console

I'm retrieving some records from a database using user = Users.all in the console but they are very unreadable.

I know that Yaml will make it more legible but don't know how to convert the results to Yaml.

Upvotes: 2

Views: 6345

Answers (4)

Bijan
Bijan

Reputation: 26507

If you want your output to be ready for Rails fixtures then restrict it to the attributes:

User.all.each {|u| y u.attributes}

Upvotes: 0

nduro
nduro

Reputation: 182

You can also just prepend a 'y' to your command in the console:

y User.all

To get yaml output.

Upvotes: 2

Seralto
Seralto

Reputation: 1076

You can type "y _" after the output like:

User.all
y _

Upvotes: 0

Amadan
Amadan

Reputation: 198418

require 'yaml'
puts user.to_yaml

Upvotes: 6

Related Questions