Stack Level Too Deep, Maybe recursive but not sure

74 views Asked by At

I'm getting a Stack Level too deep error and I think it's to do with the following code but i'm not sure how to fix it:

   after_save :update_milestone

   def update_milestone
      if order % 50 == 0
         self.update_attributes(is_milestone: true)
      else
         self.update_attributes(is_milestone: false)
      end
   end

Any thoughts

1

There are 1 answers

1
willmanduffy On BEST ANSWER

You are calling update_attributes which hits validations. This then triggers the callback after_save which is causing the errors.

You want:

self.update_column(:is_milestone, value)

This won't trigger validations.