Forum: Ruby on Rails after_create and after_save

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3518ff338e5eee9b32eb1815daabc602?d=identicon&s=25 Marcelo Barbudas (Guest)
on 2009-03-29 19:59
(Received via mailing list)
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.
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-03-29 20:18
(Received via mailing list)
On Mar 29, 6:59 pm, Marcelo Barbudas <nos...@gmail.com> 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
Ad97d898eefbb44ba50c07ee8554781b?d=identicon&s=25 Richard Mcintyre (mackstar)
on 2009-03-30 03:45
(Received via mailing list)
after_save works on both create and updates, you will need to use
after_update...??

Richard
This topic is locked and can not be replied to.