在我们的Rails 3.2的应用程序,我们需要检索所有客户记录了客户表,并将其分配给一个变量customers
并做查询(如。凡(:主动=>真)可变customers
下旬有2问题在这里:。如何高效地检索rails 3.2中的所有记录并将它们分配给可查询的对象?
有什么更好的方式来获取所有记录
Customer.all
作品然而,根据轨道的文件,它可能有性能问题时,客户表变大,我们试图Customer.find_each
它有错误"no block given (yield)"
。如何使变量
customers
query_able?当对可变
customers
查询(如customers.where(:active => true)
),有一个错误:undefined method
其中”为#. It seems that the
客户is an array object and can't take
其中. How can we retrieve
客户`以这样的方式也可以是可查询?
感谢您的帮助。
在我们的Rails 3.2.12范围的作品。谢谢。顺便说一下,它在轨道4中被弃用了吗? – user938363 2013-02-23 21:03:55
是的,它已被弃用。在Rails 4中,'all'方法相当于'scoped' – 2013-02-24 09:41:08