Skip to content

Commit

Permalink
lml#347: Cache user settings in session.
Browse files Browse the repository at this point in the history
  • Loading branch information
navilan committed Jun 15, 2014
1 parent ad65a41 commit 95f3f63
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
7 changes: 6 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class ApplicationController < ActionController::Base
:present_user,
:view_dir,
:view_dir_from_string,
:enable_clock
:enable_clock,
:user_settings

unless Ost::Application.config.consider_all_requests_local
rescue_from Exception, :with => :rescue_from_exception
Expand Down Expand Up @@ -247,4 +248,8 @@ def read_errors(object)
@errors_object = object
end

def user_settings
session[:user_settings] ||= UserSettings.for(present_user)
end

end
5 changes: 2 additions & 3 deletions app/controllers/user_settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ class UserSettingsController < ApplicationController
skip_before_filter :authenticate_user!

def index
@settings = UserSettings.for(present_user)
@settings = user_settings
end

def update
@settings = UserSettings.for(present_user)
@settings = user_settings
respond_to do |format|
if @settings.update_attributes(params[:settings])
format.json { render json: {:success => true, message: 'Settings were successfully updated.'}}
Expand All @@ -19,5 +19,4 @@ def update
end
end
end

end
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<%= render :partial => 'layouts/common_head_includes' %>
<% if current_user.present? %>
<% ost_user_settings = UserSettings.for(present_user) %>
<% ost_user_settings = user_settings %>
<script type="text/javascript">
window.OSTUserSettings = <%= raw ost_user_settings.settings.to_json %>;
</script>
Expand Down

0 comments on commit 95f3f63

Please sign in to comment.