Rails only displays messages from users that the current user is following.

I am new to Rails and going through a twitter web application.

The "next" and "supporters" of the application are excellent. However, I want to filter out the Posts index to only show posts that the current user is following.

I need to do something line by line:

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

As I expected, this causes an error

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

It seems to me that I want, because 8.9 is the identifier of my friends.

Any suggestions on the best way to get what I'm looking for?

Thank!

+3
source share
1 answer

Try INinstead LIKE:

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

Or:

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

Source: https://habr.com/ru/post/1787070/


All Articles