mardi 3 octobre 2017

Multiple after_update callbacks with attribute change conditions are triggering only the first one

Multiple after_update callbacks with attribute change conditions are triggering only the first one.

class Article < ActiveRecord::Base
  after_update :method_1, :if => proc{ |obj| obj.status_changed? && obj.status == 'PUBLISHED' }
  after_update :method_2, :if => proc{ |obj| obj.status_changed? && obj.status == 'PUBLISHED' && obj.name == 'TEST' }
  ...
end

method_1 is triggered when a model object is updated:

Article.last.update_attributes(status: 'PUBLISHED', name: 'TEST')

While method_2 is not triggered.

Aucun commentaire:

Enregistrer un commentaire