我使用acts_as_votable gem投票支持帖子和评论。我显示用户已经投票的帖子和评论:
@upvoted_posts = @user.get_voted Post
@upvoted_comments = @user.get_voted Comment
有没有办法可以在一个Feed中一起显示upvoted的帖子和评论?
答案 0 :(得分:0)
如果user.rb
user has_many :posts
中执行此类操作
def all_post_liked_by_others
@posts = Array.new
if self.posts.present?
self.posts.reload.includes(:votes).each do |p|
if p.likes.count > 0
@posts << p
end
end
return @posts.compact.flatten.uniq
else
return @posts.compact.flatten.uniq
end
end##method ends
同样,您可以定义注释方法,然后将它们合并在一起......