0

我想打电话

@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

4

2 回答 2

1

你真的不需要在控制器中访问这个集合。我想做的事情可以通过定义适当的辅助方法来解决。

于 2009-11-23T23:30:04.903 回答
0

我没有对此进行测试,但我认为它应该是 @foos.collect 而不是 @records.collect

于 2009-08-25T16:44:56.080 回答