ruby-on-railsrubyactiverecordruby-2.0hashrocket

after_commit block executes when parameter uses hashrocket syntax, but not when it uses colon syntax


I have a model that's using activerecord lifecycle callbacks pretty heavily. I'm using the after_commit callback to execute sidekiq jobs that require a primary key to run, on create.

after_commit on: :create do
  async_process
end

The code inside the block is never run.

However, when I do

after_commit :on => :create do
  async_process
end

The code runs fine.

As I understand it, these two different lines should be interpreted exactly the same way. What am I missing?

I'm using ruby 2.0.0p247, Rails 3.2.17.


Solution

  • It works for me using same Ruby and Rails versions. Alternatively, you can try with another accepted syntax:

    after_commit :async_process, on: :create