Re: Using before_save to update a record only once.

Philip Hallstrom
2007-02-28T21:35:08Z

> Philip Hallstrom wrote:
>>> What the above does is perform the action when
"completed" is set to
>>>
>>> How would I go about this? Obviously, I could add code outside the
>>> model, but before_save seems like the nicest, cleanest place to for
this
>>> code to be. I searched this forum and found a post that kind of
helps
>>> answer my question, but it''s not super clear and
I''m still not sure what
>>> the best solution is. It sounds like I have to do an external find
just
>>> to do this check, and that just doesn''t seem right to me.
Is that really
>>> the only way?
>>
>> Don''t have a specific answer for you, but the acts_as_changed
plugin
>> might come in handy for you...
>>
>> http://agilewebdevelopment.com/plugins/acts_as_changed
>>
>> -philip
>
> Thanks, Philip. I''m having a difficult time understanding exactly
what
> it does. The one line explanation isn''t 100% clear to me. It sort
of
> looks like a speed related plug-in that simply updates fields that been
> changed, rather than going through each field in the entire table, but I
> could be wrong about that.

I''ve never used it myself :)  ANd I think you''re right about
that.
There''s a "changed_attributes" method that returns
what''s changed though
that you could use perhaps...

Guess I thought it might provide more inspiration than an outright answer
:)

Thinking more about it, you could override the completed method to record
that it was changed and then check that in your before_save...

-philip