过滤器之前的 activescafold @records 操作
我想
@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 中每个对象的虚拟属性,以便在最终表中显示
thx
-C
I would like to call
@records.collect{|r| r.set_some_virtual_attribute(@context)}
before rendering an activescaffold index view, but if I do this :
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
I get :
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
when calling the index view. The same thing happens if I put the filter after the ActiveScaffold call. I would be fine with taking a different approach of some sort, but the bottom line is that I need to set a virtual attribute of each object in @records based on some context from the controller for display in the final table
thx
-C
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您实际上不需要在控制器中访问此集合。我想做的事情可以通过定义适当的辅助方法来解决。
you don't really need to access this collection in the controller. what i wanted to do can be solved with the appropriate helper methods being defined.
我还没有测试过这个,但我认为它应该是@foos.collect而不是@records.collect
I haven't testing this but i think it should be @foos.collect rather than @records.collect