Im trying to get all the Posts
from the the Users
. I'm following using the act_as_follower gem. The User follows a profile
model, and Posts
belong to a User
.
My User model:
acts_as_follower
My Profile model the user follows:
belongs_to :user
acts_as_followable
Post model:
belongs_to :user
My Post Controller.rb:
def follow
@profile = Profile.find(params[:id])
current_user.follow(@profile)
redirect_to :back
end
def unfollow
@profile = Profile.find(params[:id])
current_user.stop_following(@profile)
redirect_to :back
end
Im trying to implement something like this using follows_by_type
method provided:
@posts = current_user.follows_by_type('Post').order("created_at DESC")
But the thing is the User follows the Profile model, but here I'm looking for a type 'Post'.
EDIT
In my index controller i'v set up the following:
@favoritePost = Post.where(user_id: current_user.all_follows.pluck(:id))
And in the view iv implemented this:
<% if user_signed_in? %>
<%@favoritePost.each do |post| %>
<%= post.title %>
<% end %>
<% end %>