Continue save after before_update observer

Hi all,

I have a before_update observer method. But after that method is
finished, it doesn’t proceed to ActiveRecord’s save method. What do I
need to write in my before_update observer method to make it proceed
to the ActiveRecord save method.

This is what I wrote but it caused stack level too deep error:

class FeatureObserver < ActiveRecord::Observer
def before_update(feature)
feature.send(:save)
end
end

Thanks in advance for your help.

Kind regards,
Joshua


http://twitter.com/scrum8

On Wed, Mar 31, 2010 at 4:21 AM, Joshua P. [email protected]
wrote:

This is what I wrote but it caused stack level too deep error:

class FeatureObserver < ActiveRecord::Observer
def before_update(feature)
feature.send(:save)
end
end

:save precedes :update, so you’ve just created an infinite loop :slight_smile:

Try creating before_save, after_save, after_update methods in your
observer with some puts logging statements, and run in a console,
e.g.

feature.send(:update)
feature.send(:save)
and see what you get…


Hassan S. ------------------------ [email protected]
twitter: @hassan

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs