2015-12-02 26 views

回答

1

要獲得有關id的陣列,請嘗試:

logged_in_user_ids = Session.where(user_id: current_user.following.map(&:id)).where.not(user_id: current_user).pluck(:user_id) 

對於用戶,那麼你自己可以做:

User.where(id: logged_in_user_ids) 
+0

感謝@riarcombe 。我得到'未定義的方法user_id'。就像我以前一樣,它在'Session.where(user_id:current_user.following.map(&:user_id))。where.not(user_id:current_user).pluck(:user_id)' –

+0

OK。我通過回答編輯。我的猜測是current_user.following給你一個用戶集合...在這種情況下需要映射id。 – rlarcombe

+0

太棒了,就是這樣!謝謝@rlarcombe!我很快就會向你提供信貸。 –

相關問題