I want to make an array of hashes. But the problem is after first iteration when code goes to next line then it directly replaces the content of array.
@item_name =[]
item = {}
@invoiceinfo.each do |invoice|
item[:name] = Invoiceinfo.find(@invoiceinfo.id).item.name
item[:desc] = Invoiceinfo.find(@invoiceinfo.id).desc
item[:unit_price] = Invoiceinfo.find(@invoiceinfo.id).unit_price
byebug
@item_name.push (item)
end
This is what i am getting after first iteration suppose i have this data
@item_name = [{:name=>"usman", :desc=>"sample ", :unit_price=>100}]
As soon as next line is executed it directly changes @item_name(name variable)
After executing item[:name] = Invoiceinfo.find(@invoiceinfo.id).item.name
the content of the @item_name is changed
@item_name = [{:name=>"next_name", :desc=>"sample ", :unit_price=>100}]
Any help would be appreciated. Thannks