Вопрос

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

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top