Reputation: 3298
I have a rails application that calls the helper method in the view by:
<%= link_to_receipts @purchase_request %>
in the helper I have:
link_to_receipts purchaserequest
purchaserequest.receipts.each_with_index do |receipt,i|
#some code here commented out...
end
end
but it outputs the array like so on the view:
[#>tagged_by: "joe somebody", purchase_request_id: 39, created_at: "2011-08-22 20:39:18",updated_at: "2011-08-22 20:39:18">]
If I comment out the each_with_index it will not show the array, but if it is there it will. Any ideas?
Upvotes: 1
Views: 4191
Reputation: 3298
I found the problem. In the helper method I had the variable html first initialized in the block like so:
link_to_receipts purchaserequest
purchaserequest.receipts.each_with_index do |receipt,i|
html = ""
#more code here
end
end
When it should have been declared outside of the block:
link_to_receipts purchaserequest
html = ""
purchaserequest.receipts.each_with_index do |receipt,i|
#code here
end
end
Upvotes: 1