public-activity / public_activity

Easy activity tracking for models - similar to Github's Public Activity
MIT License
2.96k stars 334 forks source link

Custom After_Commit callback when activities are created #370

Open thejbix opened 2 years ago

thejbix commented 2 years ago

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 commented 2 years ago

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 ?

ur5us commented 2 years ago

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