How would I implement an each do loop here and leave out the comma for the last record? Code is based on here.
@h = LazyHighCharts::HighChart.new('graph') do |f|
f.series(:type=> 'pie',:name=> 'Total consumption', :data=> [
#implement a each do loop here
@products.each do |p|
{
:name=> p.name, :y=> p.price
},
end
])
end
I want the output to be:
{:name=> "Cereal", :y=> 5},
{:name=> "Dog Buscuits", :y=> 12},
{:name=> "Steak", :y=> 8} #i dont want a comma for the last record
but my current loop puts a comma in the end so i get a syntax error
{:name=> "Cereal", :y=> 5},
{:name=> "Dog Buscuits", :y=> 12},
{:name=> "Steak", :y=> 8}, #ERROR here
If you need an array as output, use map like