ActiveRecord after save new and old values

I want to write a function that after an ActiveRecord saves
successfully, can show me what the before and after values of a
particular column are. Is this possible without creating a separate
object before modifying the current one?

-John

Hi John,

Have a look at callback methods and observer classes. The following is
an example of using callback methods. Have a look at the modules
ActiveRecord::Callbacks and ActiveRecord::Observer on
http://api.rubyonrails.org/ for a full description of what is possible

class Foo
before_save :collect_before_values
after_save : collect_after_values

def collect_before_values
# …
end

def collect_after_values
# …
end
end

Hope that helps!

cheers
Martin

Doh, of course the class definition should look like

class Foo < ActiveRecord::Base

end

cheers
Martin

Thanks,

That’s exactly what I wanted.

-John

On Thu, May 18, 2006 at 07:10:30PM +0200, Martin G. wrote:


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


John O.
Systems Administrator
Yo!Africa
E-Mail: john at yoafrica.com
Tel: +263 4 858404
echo ‘9k[l:l;s<s=0l>x]s"[1+l<ddl=d-l;+ds<rl=2**l:+ds=drd+4<-d15>>]
s>[q]s-[d77/32-s;47l"x-P1+d78>`]s`0[d23/.5-3s:0l`xr10P1+d24>$]ds$x’|dc