Reputation: 4261
I have a requirement to call same method for different callbacks. Eg:-
after_create :create_feed
after_update :create_feed
after_destroy :create_feed
But, inside create_feed method, I want to know what callback triggered it (Create or Update or Delete)
Is it possible?
Upvotes: 1
Views: 262
Reputation: 3371
With something like this ?
[ :after_create, :after_update, :after_destroy ].each do |callback|
self.send(callback) { |record| record.create_feed(callback) }
end
In other words, it just creates theses lines
after_create { |record| record.create_feed(:after_create) }
after_update { |record| record.create_feed(:after_update) }
after_destroy { |record| record.create_feed(:after_destroy) }
Upvotes: 1