Answer the question
In order to leave comments, you need to log in
Is it possible in rails to override both save and save! with one function?
Hello.
Is it possible in rails to override both save
and save!
for a model with a single function?
Looking at the source, I found that both of these functions call a function with_transaction_returning_status
. Is it possible to somehow hang up an event to write an object to the database, or do both of these functions need to be redefined?
Or am I going the wrong way at all? The goal is similar to the fact that, for example, when adding a post to the database, I need to add it to the user's feed in elasticsearch. At the same time, I do not want to think every time which method is called, save or save!
If it is customary to do this differently, I ask for help :)
Thank you in advance!
Answer the question
In order to leave comments, you need to log in
No need to override, but just hang up calling your method on callback before_save or after_save
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question