1

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?

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.