From 02b1f7841016cef05a49b64f73976eb19d55255b Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 4 Jun 2013 12:56:12 -0400 Subject: [PATCH] FIX: Include preloaded data even if the request type isn't explicitly text/html --- app/controllers/application_controller.rb | 26 ++++++++++++----------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 30fe6513c0f..34180883f59 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -97,21 +97,23 @@ class ApplicationController < ActionController::Base # If we are rendering HTML, preload the session data def preload_json - if request.format && request.format.html? - if guardian.current_user - guardian.current_user.sync_notification_channel_position - end - store_preloaded("site", Site.cached_json(current_user)) + # We don't preload JSON on xhr or JSON request + return if request.xhr? - if current_user.present? - store_preloaded("currentUser", MultiJson.dump(CurrentUserSerializer.new(current_user, root: false))) - - serializer = ActiveModel::ArraySerializer.new(TopicTrackingState.report([current_user.id]), each_serializer: TopicTrackingStateSerializer) - store_preloaded("topicTrackingStates", MultiJson.dump(serializer)) - end - store_preloaded("siteSettings", SiteSetting.client_settings_json) + if guardian.current_user + guardian.current_user.sync_notification_channel_position end + + store_preloaded("site", Site.cached_json(current_user)) + + if current_user.present? + store_preloaded("currentUser", MultiJson.dump(CurrentUserSerializer.new(current_user, root: false))) + + serializer = ActiveModel::ArraySerializer.new(TopicTrackingState.report([current_user.id]), each_serializer: TopicTrackingStateSerializer) + store_preloaded("topicTrackingStates", MultiJson.dump(serializer)) + end + store_preloaded("siteSettings", SiteSetting.client_settings_json) end