Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

are before_save callbacks executed in order declared rails

Having trouble confirming this. Are 'before_save' callbacks executed in the order that they are written?

e.g.

before_save :first, :second

def first
  #some code
end

def second
  #some code
end

Will first always be called before second? Can someone please just give a yes or no answer?

I've read the rails documentation, specifically cancelling callbacks but it doesn't directly answer this question with a yes/no.

Cheers

like image 675
Robbo Avatar asked Nov 01 '25 19:11

Robbo


1 Answers

Yes the callbacks are executed in the order that they are defined.

   after_create :do_this, :and_then_this

Possible Duplicate of Enforce an Order to Rails Callbacks

like image 135
kajal ojha Avatar answered Nov 04 '25 10:11

kajal ojha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!