A couple of callback gotchas (and a Rails 5 fix)

ActiveRecord callbacks are an easy way to run code during the different stages of your model’s life.

For example, say you have a Q&A site, and you want to be able to search through all the questions. Every time you make a change to a question, you’ll want to index it in something like ElasticSearch. Indexing takes a while and isn’t urgent, so you’ll do it in the background with Sidekiq.

This seems like the perfect time to use an after_save callback! So in your model, you’ll write something li...

 •  0 comments  •  flag
Share on Twitter
Published on March 22, 2015 16:00
No comments have been added yet.