Rails 3 public_activity, destroy record

I use public_activity gem tracking if the user creates a message. Is there a way to destroy a record of public activity when deleting a message, so in the action feed it doesn’t show something like:

A post was deleted. 

And instead, it simply deletes that particular action in the action table

Thanks.

+4
source share
2 answers

I think this is what the OP was looking for / could understand, but did not publish in the solution.

An example of a quick scenario:

The user creates a comment, so a public activity record is created for this comment (key: comment.create).

Now, let's say the user deletes his comment.

There is still activity (key: comment.create) stored in the action table, which refers to the original comment that has just been deleted.

To remove this original action together when the user deletes their corresponding activity (key: comment.create). Just follow these steps.

 #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.

+8
source

In your Post model, you can track a deleted message for deleted parts so that you can use it when you show message removal notifications. you can improve your notification “Message has been deleted”, for example, “Message with XYZ content deleted in abc time format”, for example, your Post.rb having the field: content, therefore in your Post.rb

 class Post < ActiveRecord::Base include PublicActivity::Model tracked :params => { :content => proc {|controller, model| (model.content)} } 

and in your public_activity / post / destroy.html.haml you can access the content p[:content] Or you can reject the activity record with: key => post.destroy to do this in your notification controller in the action pointer class NotificationsController <ApplicationController

 def index @activities = PublicActivity::Activity.order("created_at DESC").reject{|activity| (activity.key == "post.destroy" } 

this will not notify the details of deleting messages in notifications.

+2
source

Source: https://habr.com/ru/post/1485788/


All Articles