ruby on rails 3 - Order of execution for identical Active Record callbacks -
i have model 5 after_create
callbacks. these callbacks executed top bottom? if not, order of execution?
i know docs list precedence each callback method, don't order in multiple callbacks of same type executed.
yes, callbacks of same type being executed top bottom - can check without digging activerecord code or searching documentation, example way:
class city < activerecord::base after_create -> { log(1) } after_create -> { log(2) } after_create -> { log(3) } private def log(s) file.open("/tmp/logger.txt", "a") { |f| f.puts s } end end
now if create city
, inspect file, output be
1 2 3
Comments
Post a Comment