Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

after_save(on: :create) fired on update #12502

Closed
inkstak opened this issue Oct 11, 2013 · 5 comments
Closed

after_save(on: :create) fired on update #12502

inkstak opened this issue Oct 11, 2013 · 5 comments

Comments

@inkstak
Copy link

inkstak commented Oct 11, 2013

Here is my model, with Rails 4.0.0 (also tested with edge Rails)

class Ufo < ActiveRecord::Base
  after_save(on: :create) { do_something }
  after_save :do_something_else, on: :create
end

Both callbacks are fired on update.
I cannot use after_create until after_create is always called before after_save : I need to to control the order of my callbacks.

@dabit
Copy link

dabit commented Oct 11, 2013

I think the {on: :create} option can only be used with before_validation and after_validation callbacks.

You would need to use after_create in this case.

@acapilleri
Copy link
Contributor

save is called in update and save

@rafaelfranca
Copy link
Member

Right. The only callback that accepts on option is before_validation

@sferik
Copy link
Contributor

sferik commented Jan 28, 2016

@rafaelfranca It looks to me like after_commit also accepts the on option.

@rafaelfranca
Copy link
Member

Yes, it is true. before_validation and after_commit have on but after_save not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants