Mapping multidimensional array in rails to an array -
i have list of beers user has in cellar through cellared_beers
user has many beers
through cellared_beers
, vice versa. each cellared_beer
has data year , size attached.
i wanting display tallied results of cellared_beers user on page. right have following code counts:
beer_groups = @user.cellared_beers.count(:group => [:beer_id,:year,:size]) => {[1, 2008, "12oz"]=>1, [1, 2009, "12oz"]=>3, [1, 2010, "12oz"]=>1}
how map out can show beer attributes based on beer_id, year, size, , amount?
something like:
foo beer(beer.name), bar brewery(beer.brewery.name),2008,12oz,1 foo beer(beer.name), bar brewery(beer.brewery.name),2009,12oz,3 foo beer(beer.name), bar brewery(beer.brewery.name),2010,12oz,1
you mean in string, this?
{[1, 2008, "12oz"]=>1, [1, 2009, "12oz"]=>3, [1, 2010, "12oz"]=>1}.each.map |values,count| beer = beer.find(values[0]) "#{beer.name}, #{beer.brewery.name},#{values[1]},#{values[2]}, #{count}" end
Comments
Post a Comment