我想打电话
@records.collect{|r| r.set_some_virtual_attribute(@context)}
在渲染 activescaffold 索引视图之前,但如果我这样做:
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 中设置每个对象的虚拟属性,以便在最终表中显示
谢谢
-C