2009-08-24 73 views
0

之前,我想渲染activescaffold索引視圖之前調用activescaffold @records在操縱過濾

@records.collect{|r| r.set_some_virtual_attribute(@context)} 

,但如果我這樣做:

controller FooController < ApplicationController 
    before_filter :change_things, :only => :index 
    active_scaffold :foos 

    protected 

    def change_things 
    @records.collect{|r| r.set_some_virtual_attribute(@context)} 
    end 
end 

我得到:

You have a nil object when you didn't expect it! 
You might have expected an instance of Array. 
The error occurred while evaluating nil.collect 

當調用索引視圖。如果我在ActiveScaffold調用之後放置過濾器,也會發生同樣的情況。我可以採取一些不同的方法,但底線是我需要根據控制器的某些上下文在@records中設置每個對象的虛擬屬性以顯示在決賽表中

thx

-C

回答

1

你並不真的需要在控制器訪問此集合。我想要做的事情可以通過定義適當的幫助方法來解決。

0

我還沒有測試這一點,但我認爲它應該是@ foos.collect而非@ records.collect