Chad Thatcher
2007-Mar-04 14:41 UTC
How can I intercept AR creates/updates to automatically set fields in the table?
I would like to add functionality like the update_on/created_on etc fields and intercept updates and creates so that I can drop in data into certain fields at the last minute. I am not sure what the best Railer approach would be. Observers? Override some AR methods from within my model? Any guidance on this would be appreciated, thanks. Chad --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Conrad Taylor
2007-Mar-04 15:07 UTC
Re: How can I intercept AR creates/updates to automatically set fields in the table?
Hey Chad, you can use Rail''s callbacks to handle this for you. Thus, if you need to do some post processing of create and update actions, then one can do the following within your model classes: def after_create # do some stuff end def after_update # do some stuff end For more information, please section 19.2 of AWDwRv2 Good luck, -Conrad On 3/4/07, Chad Thatcher <chad.thatcher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I would like to add functionality like the update_on/created_on etc > fields and intercept updates and creates so that I can drop in data > into certain fields at the last minute. > > I am not sure what the best Railer approach would be. Observers? > Override some AR methods from within my model? Any guidance on this > would be appreciated, thanks. > > Chad > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Chad Thatcher
2007-Mar-04 15:26 UTC
Re: How can I intercept AR creates/updates to automatically set fields in the table?
Thanks Conrad, it was staring me in the face all this time. On 4 Mar 2007, at 15:07, Conrad Taylor wrote:> > Hey Chad, you can use Rail''s callbacks to handle this for you. Thus, > if you need to do some post processing of create and update actions, > then one can do the following within your model classes: > > def after_create > # do some stuff > end > > def after_update > # do some stuff > end > > For more information, please section 19.2 of AWDwRv2 > > Good luck, > > -Conrad > > On 3/4/07, Chad Thatcher <chad.thatcher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> I would like to add functionality like the update_on/created_on etc >> fields and intercept updates and creates so that I can drop in data >> into certain fields at the last minute. >> >> I am not sure what the best Railer approach would be. Observers? >> Override some AR methods from within my model? Any guidance on this >> would be appreciated, thanks. >> >> Chad >> >>> >> > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Chris Hall
2007-Mar-05 11:51 UTC
Re: How can I intercept AR creates/updates to automatically set fields in the table?
if you want to catch something before your models are saved, vs. after, which is what it sounds like, use before_save callback. it will be called before a create or update. On 3/4/07, Conrad Taylor <conradwt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hey Chad, you can use Rail''s callbacks to handle this for you. Thus, > if you need to do some post processing of create and update actions, > then one can do the following within your model classes: > > def after_create > # do some stuff > end > > def after_update > # do some stuff > end > > For more information, please section 19.2 of AWDwRv2 > > Good luck, > > -Conrad > > On 3/4/07, Chad Thatcher <chad.thatcher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I would like to add functionality like the update_on/created_on etc > > fields and intercept updates and creates so that I can drop in data > > into certain fields at the last minute. > > > > I am not sure what the best Railer approach would be. Observers? > > Override some AR methods from within my model? Any guidance on this > > would be appreciated, thanks. > > > > Chad > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---