2011-01-22 38 views
3

我新的Rails和具有在嘰嘰喳喳型網絡應用程序中去僅從用戶的帖子。Rails的顯示,當前用戶下

在「以下」和「跟隨者」的應用程序的一部分是好的。不過,我想過濾帖子索引,只顯示當前用戶正在關注的帖子。

我需要做的線沿線的東西:

@posts = Post.where('user_id LIKE ?', current_user.friendships ) 

如我所料此錯誤

SQLite3::SQLException: near ",": syntax error: SELECT "posts".* FROM "posts" WHERE (user_id LIKE 8,9) 

似乎拋出了接近我想要的,因爲8,9是ID的我正在關注的朋友。

任何建議,得到什麼我正在尋找最好的方法是什麼?

謝謝!

+0

正如更新TK-421的答案是關於我的問題是正確的。但我的問題有點有缺陷。如果友誼被破壞,就會產生問題。最好使用@posts = Post.where(:user_id => current_user.friends)。 – Goldy

回答

5

嘗試IN,而不是LIKE

@posts = Post.where("user_id IN (?)", current_user.friendships) 

或者:

@posts = Post.where(:user_id => current_user.friendships) 
+0

工作過!謝謝你的幫助! – Goldy