aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/application.rb14
-rw-r--r--app/controllers/body_controller.rb17
-rw-r--r--app/helpers/application_helper.rb20
3 files changed, 35 insertions, 16 deletions
diff --git a/app/controllers/application.rb b/app/controllers/application.rb
index 0241ec66e..2affefa96 100644
--- a/app/controllers/application.rb
+++ b/app/controllers/application.rb
@@ -6,7 +6,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: application.rb,v 1.16 2007-10-24 11:39:37 francis Exp $
+# $Id: application.rb,v 1.17 2007-10-30 18:52:27 francis Exp $
class ApplicationController < ActionController::Base
@@ -138,6 +138,18 @@ class ApplicationController < ActionController::Base
return request.env["REMOTE_USER"]
end
end
+
+ # Simplified links to our objects
+ # XXX See controllers/user_controller.rb controllers/body_controller.rb for inverse
+ # XXX consolidate somehow with stuff in helpers/application_helper.rb
+ # use :helper_method => :your_method_name
+ def simplify_url_part(text)
+ text.downcase!
+ text.gsub!(/ /, "-")
+ text.gsub!(/[^a-z0-9_-]/, "")
+ text
+ end
+
end
diff --git a/app/controllers/body_controller.rb b/app/controllers/body_controller.rb
index 2027e13a1..0a267118a 100644
--- a/app/controllers/body_controller.rb
+++ b/app/controllers/body_controller.rb
@@ -4,13 +4,24 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: body_controller.rb,v 1.1 2007-10-11 22:01:36 francis Exp $
+# $Id: body_controller.rb,v 1.2 2007-10-30 18:52:27 francis Exp $
class BodyController < ApplicationController
+ # XXX tidy this up with better error messages, and a more standard infrastructure for the redirect to canonical URL
def show
- @public_bodies = PublicBody.find(:all, :conditions => [ "short_name = ?", params[:short_name] ])
+ @public_bodies = PublicBody.find(:all,
+ :conditions => [ "regexp_replace(replace(lower(short_name), ' ', '-'), '[^a-z0-9_-]', '', 'g') = ?", params[:simple_short_name] ])
if @public_bodies.size > 1
- raise "Two bodies with the same short name: " . params[:short_name]
+ raise "Two bodies with the same simplified short name: " . params[:simple_short_name]
+ end
+ # If none found, then search the history of short names, and do a redirect
+ if @public_bodies.size == 0
+ @public_bodies = PublicBody.find(:all,
+ :conditions => [ "id in (select public_body_id from public_body_versions where regexp_replace(replace(lower(short_name), ' ', '-'), '[^a-z0-9_-]', '', 'g') = ?)", params[:simple_short_name] ])
+ if @public_bodies.size > 1
+ raise "Two bodies with the same historical simplified short name: " . params[:simple_short_name]
+ end
+ redirect_to show_public_body_url(:simple_short_name => simplify_url_part(@public_bodies[0].short_name))
end
@public_body = @public_bodies[0]
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 495c61b61..ee0bd877e 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.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: application_helper.rb,v 1.10 2007-10-30 17:31:31 francis Exp $
+# $Id: application_helper.rb,v 1.11 2007-10-30 18:52:27 francis Exp $
module ApplicationHelper
@@ -39,24 +39,20 @@ module ApplicationHelper
return date.strftime("%e %B %Y")
end
- # Simplified links to our objects
- # XXX See controllers/user_controller.rb for inverse
- def simplify_url_part(text)
- text.downcase!
- text.gsub!(/ /, "-")
- text.gsub!(/[^a-z0-9_-]/, "")
- text
- end
-
+
+ # Links to various models
+ # XXX consolidate with simplify_url_part in controllers/application.rb so
+ # ones with calls to simplify_url_part are only in one place
+
def request_link(info_request)
link_to h(info_request.title), show_request_url(:id => info_request)
end
def public_body_link_short(public_body)
- link_to h(public_body.short_name), show_public_body_url(:short_name => public_body.short_name)
+ link_to h(public_body.short_name), show_public_body_url(:simple_short_name => simplify_url_part(public_body.short_name))
end
def public_body_link(public_body)
- link_to h(public_body.name), show_public_body_url(:short_name => public_body.short_name)
+ link_to h(public_body.name), show_public_body_url(:simple_short_name => simplify_url_part(public_body.short_name))
end
def user_link(user)