public_activity icon indicating copy to clipboard operation
public_activity copied to clipboard

Custom After_Commit callback when activities are created

Open thejbix opened this issue 2 years ago • 2 comments

I'd like to access an after_commit callback to run custom code when an activity has been created. How can this be done?

The purpose for this is I'd like to send updates or alerts when an activity is created/updated/ or destroyed.

Using Rails 7

thejbix avatar Jun 20 '22 16:06 thejbix

Is it possible to have a model extend PublicActivity::Activity

class Activity < PublicActivity::Activity
  after_commit :base_after_commit

  def base_after_commit
    puts "After Commit for PublicActivity"
  end
end

And have PublicActivity use this new model by default instead of PublicActivity::Activity ?

thejbix avatar Jun 20 '22 17:06 thejbix

@thejbix This has been address in the following PR: https://github.com/public-activity/public_activity/pull/154. However, that PR needs work, i.e. rebasing. I haven’t had the time myself yet but feel free to take a stab at it.

ur5us avatar Jun 22 '22 04:06 ur5us