Home Rails Include Current User's Post in Timeline
Reply: 0

Rails Include Current User's Post in Timeline

user831
1#
user831 Published in May 22, 2018, 12:28 am

I have rails project where user have timeline which include posts of users which he/she follows. I made a code in Post model:

scope :of_followed_users, -> (following_users) { where user_id: following_users }

So I can show the Posts in PostController like this:

@posts = Post.where(user_id: @current_user.following)order('created_at DESC').paginate(page: params[:page], per_page: 20)

But the problem is that I want users also could see his/her posts in timeline nevertheless. What is the best practice to do that? Do I have to follow myself first? I have tried using an array where user_id: [@current_user.following, @current_user] but it just shows the current_user's post. How am I able to do this?

Thank you very much!

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.417253 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO