From d2926424d65dbf21fae1814eb67a7f2db9294f5b Mon Sep 17 00:00:00 2001
From: Sam <sam.saffron@gmail.com>
Date: Wed, 2 Apr 2014 12:47:28 +1100
Subject: [PATCH] BUGFIX: raise message bus messages after data is committed

---
 app/models/site_customization.rb | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/app/models/site_customization.rb b/app/models/site_customization.rb
index e345d7587..cf002b1af 100644
--- a/app/models/site_customization.rb
+++ b/app/models/site_customization.rb
@@ -41,7 +41,8 @@ class SiteCustomization < ActiveRecord::Base
     end
   end
 
-  after_save do
+  # calls message bus, data must be committed
+  after_commit(on: :save) do
     if stylesheet_changed?
       File.delete(stylesheet_fullpath) if File.exists?(stylesheet_fullpath)
     end
@@ -55,10 +56,9 @@ class SiteCustomization < ActiveRecord::Base
       MessageBus.publish "/file-change/#{key}", stylesheet_hash
     end
     MessageBus.publish "/header-change/#{key}", header if header_changed?
-
   end
 
-  after_destroy do
+  after_commit(on: :destroy) do
     if File.exists?(stylesheet_fullpath)
       File.delete stylesheet_fullpath
     end