When an activerecord for a "category" gets created in my rails app, I need to send the data immediately to an external system via a rest api. Currently I have the rest client api call in the after_commit callback of my "category" model.
Is this the best practice in general or is there a better pattern to use?
If so, how do I prevent the api call from executing each time I seed the database for my specs?
class Category < ActiveRecord::Base
attr_accessible ............
....more stuff....
after_commit :api_post, on: :create
def api_post
ms = RestClient.new()
ms.post :category, self.to_json(:root => true)
end
end