Reputation: 1
I am trying to send a notification based on a project's status but can't quite get the logic right - my code is running :create_slack_notify_job
after any update, however I want :create_slack_notify_job
to run only after a specific kind of update (when the project's status was changed to "Active"), not after any attribute update. My after_update
is below - any ideas on how to make that run as explained?
after_update :create_slack_notify_job,
if: Proc.new{|project|project.status_changed? && project.status == 'Active' }
Upvotes: 0
Views: 548
Reputation: 3475
If you're running Rails 5.1+ you'll want to use the method saved_changes
and friends. In particular, you probably want project.saved_change_to_attribute? :status, to: 'Active'
https://github.com/rails/rails/pull/19847
Upvotes: 2