gpt4 book ai didi

ruby-on-rails - 社交 gem,从我关注的用户那里获取帖子不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 16:47:21 27 4
gpt4 key购买 nike

我想获取我关注的用户帖子列表。在conrtoller我写:

@posts = Post.where(id: current_user.followers(User).map(&:id));

在 View 中(我使用的是haml):

- @posts.each do |post|
= render partial: 'users/post', locals: { post: post, user: @user}

_post.html.haml:

.post-title
%img.img-rounded.post-image{:src => "#{@user.avatar.url}"}/
%h4.post-name
= @user.first_name + ' ' + @user.last_name
.post-date= post.created_at.strftime('%d %b - %k:%M')
.post-content

我关注了 2 个用户,他们有帖子,但我什么也没看到。以及如何将current_user的帖子添加到所有帖子?

UPDActiveRecord 在控制台生成 SQL 查询

<Post id: 1, title: "First dream", content: "This dream about nothing", visible: false, date: "2015-06-18 09:37:00", created_at: "2015-06-18 09:38:17", updated_at: "2015-06-18 09:38:17", user_id: 1>

最佳答案

我认为不应该是:@posts = Post.where(id: current_user.followers(User).map(&:id));

但是@posts = Post.where(id: current_user.followees(User).map(&:id));

来自文档:您正在关注哪些项目(假定已关注 Item 模型)?user.followees(项目)

关于ruby-on-rails - 社交 gem,从我关注的用户那里获取帖子不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30892090/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com