0

When I do my_record.save can I pass a parameter or something to tell the record to not call it's Callback? Below is the callback I have set for my object.

class Measurable < ActiveRecord::Base

   after_save :summarize_measurables_for_player

   # ...

   def summarize_measurables_for_player
     # ...   
   end

end

Edit

This callback is used for when someone changes a value on measurable, then it calculates the preferred value for the Measurable_Type and then it stores that value on a column of another object. This allows me to retrieve the information much faster. I however, don't want this to be called when I import information. Because it would then summarize after each change. It would be a faster process to import all the information and then summarize all the values at once I would think.

daveomcd
  • 6,367
  • 14
  • 83
  • 137
  • 1
    You might find [this question and answers](http://stackoverflow.com/questions/632742/how-can-i-avoid-running-activerecord-callbacks) useful. Skip down to the answer with 166 points. I found a lot of useful hits Googling "rails skip save callback". :) – lurker Nov 17 '15 at 16:25

1 Answers1

3

In your case, I'd add an attr_accessor to the model and skip this method if set to true.

class Measurable < ActiveRecord::Base

   after_save :summarize_measurables_for_player, :unless => :skip_summarize

   attr_accessor :skip_summarize

   # ...

   def summarize_measurables_for_player
     # ...   
   end

end

Then in the import, you can set :skip_summarize => true in the attributes of the imported object.

Mark Swardstrom
  • 17,217
  • 6
  • 62
  • 70