我想在Rails上的ActiveRecord
中的where()
方法中实现一个lambda。这里是我的代码:Rails Lambda ActiveRecord
@applications.where { |app| !((calculate_days_ago(app.shipping_date) >= 10 && calculate_days_ago(:app.shipping_date) <= 19) || app.followup_calls.count == 0) }
凡@applications
是ActiveRecord
(例如Application.all
)。但是,当我试图访问它(例如order
,where
),它的类型是变化WhereChain
,我有一个例外:
未定义的方法',其中”为#ActiveRecord :: QueryMethods :: WhereChain:0x6fb1000 >
有没有一种方法可以在我的where()
条件下使用适当的返回类型实现lambda表达式?
注意:我来自C#背景,这样的lambda可以这样做,我是Ruby on Rails的新手。我不知道这个社区与downvotes bash新手。尽我所能让我的问题尽可能清楚。
你是如何将块传递给'#where'?我从来没有见过这样的文件。请链接 – 2015-02-23 09:29:35
什么是@applications?通常你会在类上调用'.where',例如'Application.where(....' – 2015-02-23 09:29:40
@JohnIsaiahCarmona你可以传递一个块给任何方法,但是它会被忽略,除非该方法调用该块。 – Stefan 2015-02-23 09:42:02