Answer the question
In order to leave comments, you need to log in
How to know if the number of records in a model has changed?
Hello.
There is a Product model, this model has pictures, which we can calculate for example like this: Product.first.pictures.size
The question is how to find out that the number of pictures for a certain product has changed after it was created or updated.
For example, for titles and descriptions, I use the method:
before_update :drop_moderation
def drop_moderation
self.status = 'on_moderation' if self.title_changed? || self.description_changed?
end
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question