Hi,
I'm working on a Newsfeed action. I have active friendships and i would like to find the posts only of those friendships to create the newsfeed.
This is the code i currently have:
@active_friendships = current_user.active_friendships
@posts = Post.where({ :user_id => [5,8,16] }).order("created_at DESC")
I don't know how to send the @active_friendships.user_id values to the IN in the second line. At the moment the code is only worked because it has hardcoded the user_id of my active friends (5,8,16).
(If i do a debug @active_friendships) i get the 3 objects with their ids, but i still don't know how to send them to the IN in the second line as the ids to look for.
--
- !ruby/object:Friendship
attributes:
created_at: 2010-10-06 22:27:54.620007
updated_at: 2010-10-07 00:19:10.329799
id: 182
user_id: 8
status: 1
friend_id: 5
attributes_cache: {}
changed_attributes: {}
destroyed: false
marked_for_destruction: false
new_record: false
previously_changed: {}
readonly: false
- !ruby/object:Friendship
attributes:
created_at: 2010-10-07 19:13:10.617959
updated_at: 2010-10-07 19:13:17.097514
id: 192
user_id: 16
status: 1
friend_id: 5
attributes_cache: {}
changed_attributes: {}
destroyed: false
marked_for_destruction: false
new_record: false
previously_changed: {}
readonly: false
- !ruby/object:Friendship
attributes:
created_at: 2010-10-10 04:12:48.931120
updated_at: 2010-10-10 04:12:56.960752
id: 214
user_id: 8
status: 1
friend_id: 5
attributes_cache: {}
changed_attributes: {}
destroyed: false
marked_for_destruction: false
new_record: false
previously_changed: {}
readonly: false
Many thanks in advance