gpt4 book ai didi

ruby-on-rails - 是否可以将 gem Unread 与 gem Public Activity 一起使用?

转载 作者:太空宇宙 更新时间:2023-11-03 17:22:29 24 4
gpt4 key购买 nike

我目前正在使用 gem“公共(public)事件”,在 View 中我过滤了一个用户事件以仅向该用户显示适用于他们的事件,例如“John Smith 评论了您的帖子”。但是,我想为此添加通知,例如 facebook 或 twitter,其中徽章显示数字,当您看到提要时徽章消失。

我找到了一个名为 Unread 的 gem,它看起来很理想,除了它需要将 acts_as_readable :on => :created_at 添加到您的模型中,并且由于我使用的是 public_activity gem,所以该类不可访问添加这个。

是否可以将未读 gem 所需的代码注入(inject)到 PublicActivity:Activity 类中?

链接:

gem 公共(public)事件:https://github.com/pokonski/public_activity

gem 未读:https://github.com/ledermann/unread

最佳答案

对于将来可能会发现这一点的任何人,我通过对自己的通知进行数据建模来实现一个完全不同的系统。我没有使用公共(public)事件和未读,而是创建了一个名为通知的新模型。这有列:

    recipient:integer
sender:integer
post_id:integer
type:string
read:boolean

然后,每当我有用户评论或点赞等时,我都会在 Controller 中构建一个新通知,传递以下信息:

    recipient = @post.user.id
sender = current_user.id
post_id = @post.id
type = "comment" # like, or comment etc
read = false # read is false by default

在导航栏中,我只是添加了一个徽章,用于根据应用程序 Controller 变量计算 current_users 未读通知。

    @unreadnotifications = current_user.notifications.where(read: false)

<% if @unreadnotifications.count != 0 %>
(<%= @unreadnotifications.count %>)
<% end %>

然后,在通知 Controller 中,我让它在 View 上运行 mark_as_read 操作。然后将通知计数设置回 0。

    before_action :mark_as_read

def mark_as_read
@unread = current_user.notifications.where(read: false)
@unread.each do |unread|
unread.update_attribute(:read, true)
end
end

关于ruby-on-rails - 是否可以将 gem Unread 与 gem Public Activity 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29263920/

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