diff options
-rw-r--r-- | app/controllers/public_body_controller.rb | 6 | ||||
-rw-r--r-- | app/models/public_body.rb | 16 | ||||
-rw-r--r-- | app/views/admin_public_body/_form.rhtml | 2 | ||||
-rw-r--r-- | app/views/admin_public_body/import_csv.rhtml | 2 | ||||
-rw-r--r-- | app/views/public_body/list.rhtml | 2 | ||||
-rw-r--r-- | config/environment.rb | 1 | ||||
-rw-r--r-- | config/environments/development.rb | 4 |
7 files changed, 18 insertions, 15 deletions
diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb index 21ef45677..0ec9f1a32 100644 --- a/app/controllers/public_body_controller.rb +++ b/app/controllers/public_body_controller.rb @@ -4,7 +4,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: public_body_controller.rb,v 1.6 2009-09-07 17:31:36 francis Exp $ +# $Id: public_body_controller.rb,v 1.7 2009-09-10 14:59:35 francis Exp $ class PublicBodyController < ApplicationController # XXX tidy this up with better error messages, and a more standard infrastructure for the redirect to canonical URL @@ -68,7 +68,7 @@ class PublicBodyController < ApplicationController @tag = "all" conditions = [] elsif @tag == 'other' - category_list = PublicBody.categories.map{|c| "'"+c+"'"}.join(",") + category_list = PublicBody::CATEGORIES.map{|c| "'"+c+"'"}.join(",") conditions = ['(select count(*) from public_body_tags where public_body_tags.public_body_id = public_bodies.id and public_body_tags.name in (' + category_list + ')) = 0'] elsif @tag.size == 1 @@ -85,7 +85,7 @@ class PublicBodyController < ApplicationController if @tag.size == 1 @description = "beginning with '" + @tag + "'" else - @description = PublicBody.categories_by_tag[@tag] + @description = PublicBody::CATEGORIES_BY_TAG[@tag] if @description.nil? @description = @tag end diff --git a/app/models/public_body.rb b/app/models/public_body.rb index 1ab9ecf37..61554a38b 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -26,7 +26,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: public_body.rb,v 1.154 2009-09-10 13:34:34 francis Exp $ +# $Id: public_body.rb,v 1.155 2009-09-10 14:59:35 francis Exp $ require 'csv' require 'set' @@ -44,7 +44,7 @@ class PublicBody < ActiveRecord::Base has_many :public_body_tags has_many :track_things, :order => 'created_at desc' - categories_with_headings = [ + CATEGORIES_WITH_HEADINGS = [ "Miscellaneous", [ "other", "Miscellaneous", "miscellaneous" ], "Central government", @@ -118,10 +118,10 @@ class PublicBody < ActiveRecord::Base [ "scp", "Safety Camera Partnerships", "a safety camera partnership" ], [ "srp", "Safer Roads Partnership", "a safer roads partnership" ] ] - categories_with_description = categories_with_headings.select() { |a| a.instance_of?(Array) } - categories = categories_with_description.map() { |a| a[0] } - categories_by_tag = Hash[*categories_with_description.map() { |a| a[0..1] }.flatten] - category_singular_by_tag = Hash[*categories_with_description.map() { |a| [a[0],a[2]] }.flatten] + CATEGORIES_WITH_DESCRIPTION = CATEGORIES_WITH_HEADINGS.select() { |a| a.instance_of?(Array) } + CATEGORIES = CATEGORIES_WITH_DESCRIPTION.map() { |a| a[0] } + CATEGORIES_BY_TAG = Hash[*CATEGORIES_WITH_DESCRIPTION.map() { |a| a[0..1] }.flatten] + CATEGORY_SINGULAR_BY_TAG = Hash[*CATEGORIES_WITH_DESCRIPTION.map() { |a| [a[0],a[2]] }.flatten] # like find_by_url_name but also search historic url_name if none found def self.find_by_url_name_with_historic(name) @@ -303,8 +303,8 @@ class PublicBody < ActiveRecord::Base types = [] first = true for tag in self.public_body_tags - if PublicBody.categories_by_tag.include?(tag.name) - desc = PublicBody.category_singular_by_tag[tag.name] + if PublicBody::CATEGORIES_BY_TAG.include?(tag.name) + desc = PublicBody::CATEGORY_SINGULAR_BY_TAG[tag.name] if first # terrible that Ruby/Rails doesn't have an equivalent of ucfirst # (capitalize shockingly converts later characters to lowercase) diff --git a/app/views/admin_public_body/_form.rhtml b/app/views/admin_public_body/_form.rhtml index 12cb80db8..97c4d47c9 100644 --- a/app/views/admin_public_body/_form.rhtml +++ b/app/views/admin_public_body/_form.rhtml @@ -5,7 +5,7 @@ <div id="tag_help"> <h2>List of tags</h2> <% first_row = true %> - <% for row in PublicBody.categories_with_headings %> + <% for row in PublicBody::CATEGORIES_WITH_HEADINGS %> <% if row.instance_of?(Array) %> <% if row[0] != 'other' %> <strong><%= row[0] %></strong>=<%= row[1] %> diff --git a/app/views/admin_public_body/import_csv.rhtml b/app/views/admin_public_body/import_csv.rhtml index 9c0ead145..a3249e284 100644 --- a/app/views/admin_public_body/import_csv.rhtml +++ b/app/views/admin_public_body/import_csv.rhtml @@ -13,7 +13,7 @@ <% form_tag 'import_csv', :multipart => true do %> <p> <label for="tag">Tag to add entries to (maybe you want: - <% for category, description in PublicBody.categories_by_tag %> + <% for category, description in PublicBody::CATEGORIES_BY_TAG %> <% if category != "other" %> <strong><%= category %></strong>=<%= description %>; <% end %> diff --git a/app/views/public_body/list.rhtml b/app/views/public_body/list.rhtml index 8496fdd35..18314f815 100644 --- a/app/views/public_body/list.rhtml +++ b/app/views/public_body/list.rhtml @@ -8,7 +8,7 @@ </li></ul> <% first_row = true %> -<% for row in PublicBody.categories_with_headings %> +<% for row in PublicBody::CATEGORIES_WITH_HEADINGS %> <% if row.instance_of?(Array) %> <li> <%= link_to_unless (@tag == row[0]), row[1], list_public_bodies_url(:tag => row[0]) %> diff --git a/config/environment.rb b/config/environment.rb index 85e23e8a4..46eaa32b4 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -135,4 +135,3 @@ require 'activesupport_cache_extensions.rb' # XXX temp debug for SQL logging production sites #ActiveRecord::Base.logger = Logger.new(STDOUT) - diff --git a/config/environments/development.rb b/config/environments/development.rb index 1cf3222b5..6f2531dfa 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -17,3 +17,7 @@ config.action_view.debug_rjs = true config.action_mailer.raise_delivery_errors = false config.action_mailer.delivery_method = :sendmail # so is queued, rather than giving immediate errors +require 'memory_profiler' +MemoryProfiler.start :string_debug => true, :delay => 10 + + |