Search code examples
ruby-on-railsmodelcallbackstack-level

Stack Level Too Deep, Maybe recursive but not sure


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


Solution

  • 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.