2015-05-24 36 views
0

我是ruby和rails的新手,我有一個使用社交化gem的rails應用程序。該gem附帶一個「followees」方法,返回當前用戶「跟隨」的用戶數組。我正在嘗試編寫一個查詢,它將按用戶創建的順序返回最近創建的所有帖子。Rails - 從參數中查找所有內容

我想這一點,

@subscribed = current_user.followees(User).all.posts.order('created_at DESC') 

,但我得到的錯誤

undefined method `all' for #<Array:0x0000000d5ce0b0> 

就像你說的任何幫助表示讚賞

回答

3

#followees返回Array,它不具有#all方法。

相反,你需要直接查詢Post型號如下:

followers = current_user.followees(User) 
followers_posts = Post.where(user: followers).all