我想在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