将数组写入文件ruby

时间:2017-10-20 17:03:15

标签: ruby-on-rails ruby

我有一系列品牌。

我有这段代码:

brands.each_with_index do |brand, index|
  File.open('brands.txt', 'w') { |file| file.print  "#{brand.name} - #{brand.url}" }
end

所以我想将所有品牌写入档案,但结果我只获得了最后一个品牌,如下所示:

  

Biomill - htttp://site.com/brand/biomill/dogs/

好像我的文件正在循环中被重写。 我该怎么办?

1 个答案:

答案 0 :(得分:3)

你几乎拥有它!

<div class="video-player">
<div class="video-tree">
<video id="myVideo1" poster="someimage.png" width="430" height="250" controls>
<source src="someVideo.mp4" type="video/mp4"> 
</video>
</div> <!-- end video-tree class -->
</div><!-- end video-player class -->