Hi all, I''m running into a brick wall trying to figure out my problem here. I have a model that has a boolean property called "paid". I''d like to add the following to my model: def after_save self.amount == self.splits.sum(:amount) ? self.update_attribute (:paid, true) : self.update_attribute(:paid, false) end The problem is, when I do this I get an error that my stack level is too deep. If I throw this in with one of the model''s validators it works just fine, but that''s not the right way to do this... I don''t see how I''m recursing here, so any help would be appreciated! Thanks! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You should update by sql in after_save. On Sun, Jan 18, 2009 at 12:34 PM, Neal L <neal.lober-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi all, > > I''m running into a brick wall trying to figure out my problem here. I > have a model that has a boolean property called "paid". I''d like to > add the following to my model: > > def after_save > self.amount == self.splits.sum(:amount) ? self.update_attribute > (:paid, true) : self.update_attribute(:paid, false) > end > > > The problem is, when I do this I get an error that my stack level is > too deep. If I throw this in with one of the model''s validators it > works just fine, but that''s not the right way to do this... > > I don''t see how I''m recursing here, so any help would be appreciated! > > Thanks! > > >-- TWRUG Blog: http://blog.rubyonrails.org.tw CFC on Rails: http://zusocfc.blogspot.com Only two surfaces of a box: http://blog.pixnet.net/zusocfc --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
update_attribute saves the updated record, so after_save will be called again, hence the recursion. Colin --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---