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.
Marcelo B. (Guest)
on 2009-03-29 21: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.
Frederick C. (Guest)
on 2009-03-29 22:18
(Received via mailing list)
On Mar 29, 6:59 pm, Marcelo B. <removed_email_address@domain.invalid> 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
Richard M. (Guest)
on 2009-03-30 05: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.