diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/general_controller.rb | 42 | ||||
-rw-r--r-- | app/models/track_mailer.rb | 7 | ||||
-rw-r--r-- | app/models/user.rb | 7 |
3 files changed, 26 insertions, 30 deletions
diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index faf34aa04..003b815d3 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -19,26 +19,28 @@ class GeneralController < ApplicationController # New, improved front page! def frontpage medium_cache - # get some example searches and public bodies to display - # either from config, or based on a (slow!) query if not set - body_short_names = Configuration::frontpage_publicbody_examples.split(/\s*;\s*/).map{|s| "'%s'" % s.gsub(/'/, "''") }.join(", ") - @locale = self.locale_from_params() - locale_condition = 'public_body_translations.locale = ?' - conditions = [locale_condition, @locale] - I18n.with_locale(@locale) do - if body_short_names.empty? - # This is too slow - @popular_bodies = PublicBody.visible.find(:all, - :order => "info_requests_count desc", - :limit => 32, - :conditions => conditions, - :joins => :translations - ) - else - conditions[0] += " and public_bodies.url_name in (" + body_short_names + ")" - @popular_bodies = PublicBody.find(:all, - :conditions => conditions, - :joins => :translations) + behavior_cache :tag => [session[:user_id], request.url] do + # get some example searches and public bodies to display + # either from config, or based on a (slow!) query if not set + body_short_names = Configuration::frontpage_publicbody_examples.split(/\s*;\s*/).map{|s| "'%s'" % s.gsub(/'/, "''") }.join(", ") + @locale = self.locale_from_params() + locale_condition = 'public_body_translations.locale = ?' + conditions = [locale_condition, @locale] + I18n.with_locale(@locale) do + if body_short_names.empty? + # This is too slow + @popular_bodies = PublicBody.visible.find(:all, + :order => "info_requests_count desc", + :limit => 32, + :conditions => conditions, + :joins => :translations + ) + else + conditions[0] += " and public_bodies.url_name in (" + body_short_names + ")" + @popular_bodies = PublicBody.find(:all, + :conditions => conditions, + :joins => :translations) + end end end # Get some successful requests diff --git a/app/models/track_mailer.rb b/app/models/track_mailer.rb index 7dfa87f52..03310478a 100644 --- a/app/models/track_mailer.rb +++ b/app/models/track_mailer.rb @@ -91,10 +91,9 @@ class TrackMailer < ApplicationMailer if email_about_things.size > 0 # Send the email - previous_locale = I18n.locale - I18n.locale = user.get_locale - TrackMailer.deliver_event_digest(user, email_about_things) - I18n.locale = previous_locale + I18n.with_locale(user.get_locale) do + TrackMailer.deliver_event_digest(user, email_about_things) + end end # Record that we've now sent those alerts to that user diff --git a/app/models/user.rb b/app/models/user.rb index 490587c39..bc04b5449 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -90,12 +90,7 @@ class User < ActiveRecord::Base end def get_locale - if !self.locale.nil? - locale = self.locale - else - locale = I18n.locale - end - return locale.to_s + (self.locale || I18n.locale).to_s end def visible_comments |