diff options
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/admin_public_body_controller.rb | 12 | ||||
-rw-r--r-- | app/controllers/general_controller.rb | 15 | ||||
-rw-r--r-- | app/controllers/public_body_controller.rb | 2 |
3 files changed, 20 insertions, 9 deletions
diff --git a/app/controllers/admin_public_body_controller.rb b/app/controllers/admin_public_body_controller.rb index 3e0613a1f..98d4c1044 100644 --- a/app/controllers/admin_public_body_controller.rb +++ b/app/controllers/admin_public_body_controller.rb @@ -23,11 +23,13 @@ class AdminPublicBodyController < AdminController if @page == "" @page = nil end - @public_bodies = PublicBody.paginate :order => "name", :page => @page, :per_page => 100, - :conditions => @query.nil? ? nil : ["lower(name) like lower('%'||?||'%') or - lower(short_name) like lower('%'||?||'%') or - lower(request_email) like lower('%'||?||'%')", @query, @query, @query] - @public_bodies_by_tag = PublicBody.find_by_tag(@query) + @public_bodies = PublicBody.paginate :order => "public_body_translations.name", :page => @page, :per_page => 100, + :conditions => @query.nil? ? "public_body_translations.locale = '#{@locale}'" : + ["(lower(public_body_translations.name) like lower('%'||?||'%') or + lower(public_body_translations.short_name) like lower('%'||?||'%') or + lower(public_body_translations.request_email) like lower('%'||?||'%' )) AND (public_body_translations.locale = '#{@locale}')", @query, @query, @query], + :joins => :translations + @public_bodies_by_tag = PublicBody::Translation.find_by_tag(@query) end end diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index cf28208a0..bdbcfcdd4 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -20,9 +20,19 @@ class GeneralController < ApplicationController # New, improved front page! def frontpage - behavior_cache do # This is too slow - @popular_bodies = PublicBody.find(:all, :select => "*, (select count(*) from info_requests where info_requests.public_body_id = public_bodies.id) as c", :order => "c desc", :limit => 32) + @locale = self.locale_from_params() + locale_condition = 'public_body_translations.locale = ?' + conditions = [locale_condition, @locale] + PublicBody.with_locale(@locale) do + @popular_bodies = PublicBody.find(:all, + :select => "public_bodies.*, (select count(*) from info_requests where info_requests.public_body_id = public_bodies.id) as c", + :order => "c desc", + :limit => 32, + :conditions => conditions, + :joins => :translations + ) + end # Get some successful requests # begin query = 'variety:response (status:successful OR status:partially_successful)' @@ -34,7 +44,6 @@ class GeneralController < ApplicationController rescue @successful_request_events = [] end - end end # Display WhatDoTheyKnow category from mySociety blog diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb index e790b042f..2d1577600 100644 --- a/app/controllers/public_body_controller.rb +++ b/app/controllers/public_body_controller.rb @@ -20,7 +20,7 @@ class PublicBodyController < ApplicationController PublicBody.with_locale(@locale) do @public_body = PublicBody.find_by_url_name_with_historic(params[:url_name]) raise "None found" if @public_body.nil? # XXX proper 404 - + return redirect_to :back if @public_body.url_name.nil? # If found by historic name, redirect to new name redirect_to show_public_body_url(:url_name => @public_body.url_name) if @public_body.url_name != params[:url_name] |