ostr = '{ "data": ['
 articles = Article.order("created_at DESC")

  ostr = ostr + articles.map{|f| ' ["' + f.title.chomp + '", "' + f.file_url + '"] '}.join(', ')
  ostr = ostr + "]}"

map 會把activerecord取出來,設給f 然後組字串,最後加上join

這樣就像implode功能,效果很好~~