我需要創建一個XML文件輸出,如:如何使用Rails生成XML?
<data>
<hour>0</hour>
<count>8</count>
</data>
.
.
<data>
<hour>23</hour>
<count>1</count>
</data>
我寫在我的控制器下面的代碼:
for @k in (0..23)
@data.push(Datum.new(@k,@freq[@k]));
end
class Datum
def initialize(hour, count)
@hour = hour
@count = count
end
end
render xml:@data
但輸出出來,如:
tweet-densities-controller-data type="array">
<tweet-densities-controller-datum type="TweetDensitiesController::Datum">#
TweetDensitiesController::Datum:0xacbddc4></tweet-densities-controller-datum>