Hi, AFAIK after_create is called after_save if the entry does not exist in the DB. Is there a way to tell if a specific model is new or not in after_save? I have to do something like: def after_save add_to_history ''save'' end def after_create add_to_history ''create'' end However after_save is called when creating too. -- cheers, M. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Mar 29, 6:59 pm, Marcelo Barbudas <nos...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > AFAIK after_create is called after_save if the entry does not exist in > the DB. > > Is there a way to tell if a specific model is new or not in > after_save? >This doesn''t directly answer your question but may still address the root concern: take a look at after_update. Fred> I have to do something like: > def after_save > add_to_history ''save'' > end > > def after_create > add_to_history ''create'' > end > > However after_save is called when creating too. > > -- > cheers, > M.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
after_save works on both create and updates, you will need to use after_update...?? Richard On Mar 30, 2:59 am, Marcelo Barbudas <nos...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > AFAIK after_create is called after_save if the entry does not exist in > the DB. > > Is there a way to tell if a specific model is new or not in > after_save? > > I have to do something like: > def after_save > add_to_history ''save'' > end > > def after_create > add_to_history ''create'' > end > > However after_save is called when creating too. > > -- > cheers, > M.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---