2012-05-11 47 views

回答

6
require 'yaml' 
puts user.to_yaml 
+1

感謝,我認爲我以前做過,而不必使用'puts'。一旦系統允許我接受答案。 – Leahcim

2

你也可以在前面加上 'Y' 你的命令控制檯:

y User.all 

要獲得YAML輸出。

+0

這對'zeus console'中的我不起作用 - 我得到:「NoMethodError:undefined method'y'for main:Object」 – redtree

0

您可以像輸出後鍵入「Y _」:

User.all 
y _ 
0

如果你希望你的輸出做好準備爲Rails燈具則限制的屬性:

User.all.each {|u| y u.attributes} 
相關問題