【发布时间】:2009-11-24 07:30:04
【问题描述】:
我想打电话
@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
【问题讨论】:
标签: ruby-on-rails callback activescaffold