2011-08-22 84 views
1

我有通過調用輔助方法在視圖中軌應用:在輔助我有each_with_index正在輸出陣列

<%= link_to_receipts @purchase_request %> 

link_to_receipts purchaserequest 
    purchaserequest.receipts.each_with_index do |receipt,i| 
    #some code here commented out... 
    end 
end 

但它像這樣的陣列輸出在視圖:

[#> tagged_by: 「喬某人」,purchase_request_id:39,created_at:「 2011-08-22 20點39分18" 秒,的updated_at: 「2011-08-22 20點39分18秒」>]

如果我註釋掉它不會顯示該陣列的each_with_index,但如果它在那裏,它會。有任何想法嗎?

回答

1

我發現了這個問題。在輔助方法,我有變量HTML塊中的第一次初始化像這樣:

link_to_receipts purchaserequest 
    purchaserequest.receipts.each_with_index do |receipt,i| 
    html = "" 
    #more code here 
    end 
end 

當它應該被宣佈塊外:

link_to_receipts purchaserequest 
html = "" 
    purchaserequest.receipts.each_with_index do |receipt,i| 
    #code here 
    end 
end