过滤器之前的 activescafold @records 操作

发布于 2024-08-02 23:16:35 字数 739 浏览 5 评论 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 中每个对象的虚拟属性,以便在最终表中显示

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

GRAY°灰色天空 2024-08-09 23:16:35

您实际上不需要在控制器中访问此集合。我想做的事情可以通过定义适当的辅助方法来解决。

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.

幸福%小乖 2024-08-09 23:16:35

我还没有测试过这个,但我认为它应该是@foos.collect而不是@records.collect

I haven't testing this but i think it should be @foos.collect rather than @records.collect

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文