How to save a model without running callbacks in Rails

后端 未结 8 2466
青春惊慌失措
青春惊慌失措 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:45

    For Rails 3 ActiveSupport::Callbacks gives you the necessary control. You can reset_callbacks en-masse, or use skip_callback to disable judiciously like this:

    Vote.skip_callback(:save, :after, :add_points_to_user)
    

    …after which you can operate on Vote instances with :add_points_to_user inhibited

提交回复
热议问题