Rails 3 public_activity,销毁记录 [英] Rails 3 public_activity, destroy record

查看:50
本文介绍了Rails 3 public_activity,销毁记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果用户创建帖子,我将使用 public_activity gem 跟踪.有没有办法在删除帖子时销毁公共活动记录,以便在活动提要中不显示以下内容:

I am using the public_activity gem tracking if a user creates a post. Is there a way to destroy a public activity record, on deletion of the post, so that in the activities feed it doesn't show something like:

A post was deleted.

而只是删除活动表中的特定活动

And instead just deletes that particular activity in the activities table

谢谢.

推荐答案

我认为这就是 OP 正在寻找的/可能已经想到的,但没有在解决方案中发布.

I think this is what the OP was looking for / may have figured out, but didn't post in a solution.

快速示例场景:

用户创建了一条评论,因此会为该评论创建一个公共活动记录(键:comment.create).

A user creates a comment, therefore a Public Activity Record (key: comment.create) is created for that comment.

现在,假设用户删除了他的评论.

Now, lets say the user deletes his comment.

在活动表中还有一个活动(键:comment.create)与刚刚被删除的原始评论相关.

There is still an activity (key: comment.create) stored in the activities table that relates to the original comment that just got deleted.

当用户删除其相应的活动(键:comment.create)时,一起删除该原始活动.只需执行以下操作.

To delete that original activity all together when a user deletes their corresponding activity (key: comment.create). Simply do the following.

#comments_controller.rb or whatever class you are tracking
def destroy
  @comment = current_user.comments.find(params[:id])
  @activity = PublicActivity::Activity.find_by(trackable_id: (params[:id]), trackable_type: controller_path.classify)
  @activity.destroy
  @comment.destroy
end

希望这对某人有所帮助.

Hope this helps someone.

这篇关于Rails 3 public_activity,销毁记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆