How to save a model without running callbacks in Rails

后端 未结 8 2446
青春惊慌失措
青春惊慌失措 2020-12-29 04:55

I need to calculate values when saving a model in Rails. So I call calculate_averages as a callback for a Survey class:

before_save         


        
8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-29 05:44

    hopefully this is what you're looking for.

    https://stackoverflow.com/a/6587546/2238259

    For your second issue, I suspect it would be better to inspect when this calculation needs to happen, it would be best if it could be handled in batch at a specified time where network traffic is at its trough.

    EDIT: Woops. I actually found 2 links but lost the first one, apparently. Hopefully you have it fixed.

提交回复
热议问题