Ruby on rails:将多行存储在不同的数组中

时间:2016-01-03 18:44:43

标签: mysql ruby-on-rails arrays ruby

我是Ruby on rails的初学者,我的请求sql有些问题。

首先我有这个要求:

Annonce.find_by_sql(
    "SELECT annonces.TitreAnnonce, annonces.Coins, categories.nom,
            regions.Nom as NomRegion  
     FROM annonces 
     INNER JOIN categories, regions 
     WHERE annonces.idCategories = categories.id and annonces.idRegions = regions.id 
     ORDER BY annonces.id DESC LIMIT 6")

我想将每一行存储在不同的数组中。我使用map{ |f| "#{f.nom} #{f.NomRegion} #{f.TitreAnnonce} #{f.Coins}"}但结果存储在一个唯一的数组中。

我的第二个问题如下。当我在html.erb文件中发出请求时,结果显示在我的网页底部,如下所示:

[["Title1", 1500, "Car", "Quebec"], ["Title2", 50, "Car", "Title3"], ["Title4", 130, "Car", "Quebec"]]

如何才能显示此结果。

0 个答案:

没有答案