This looks like a task for before_create for me. If you need to save your after_* , you probably should use the before_* .
In before_create you will not need to call save , since saving occurs after the callback code is executed.
Instead of saving a view request, if you receive 2 or more objects, you should request one object that will conflict before saving.
In the psuedo code that you have now:
after creation now that I'm saved, find all tasks in my room and at my time did I find more than one? Am I the first one? yes: add note about another task, then save again no: everything is fine, no need to re-save any edits
What you should have:
before creation is there at least 1 task in this room at the same time? yes: add note about another task no: everything is fine, allow saving without modification
Something else like this:
before_create :check_room_schedule def check_room_schedule conflicting_task = Task.for_date(self.day) .for_room(self.room) .where(begin: self.begin)
source share