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
Martin Gamsjaeger
2006-May-18 17:10 UTC
[Rails] ActiveRecord after save new and old values
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 On 5/18/06, John Oxley <john@yoafrica.com> wrote:> 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 > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Martin Gamsjaeger
2006-May-18 17:12 UTC
[Rails] ActiveRecord after save new and old values
Doh, of course the class definition should look like class Foo < ActiveRecord::Base # ... end cheers Martin On 5/18/06, Martin Gamsjaeger <gamsnjaga@gmail.com> wrote:> 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 > > On 5/18/06, John Oxley <john@yoafrica.com> wrote: > > 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 > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
Thanks, That''s exactly what I wanted. -John On Thu, May 18, 2006 at 07:10:30PM +0200, Martin Gamsjaeger wrote:> 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 > > On 5/18/06, John Oxley <john@yoafrica.com> wrote: > >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 > >_______________________________________________ > >Rails mailing list > >Rails@lists.rubyonrails.org > >http://lists.rubyonrails.org/mailman/listinfo/rails > >> _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-- John Oxley 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<dd*l=d*-l;+ds<rl=2**l:+ds=d*rd*+4<-d15>>] s>[q]s-[d77/3*2-s;47l"x-P1+d78>`]s`0[d23/.5-3*s:0l`xr10P1+d24>$]ds$x''|dc