diff options
-rw-r--r-- | app/controllers/request_controller.rb | 4 | ||||
-rw-r--r-- | app/controllers/user_controller.rb | 5 | ||||
-rw-r--r-- | app/helpers/application_helper.rb | 15 | ||||
-rw-r--r-- | app/views/body/show.rhtml | 2 | ||||
-rw-r--r-- | app/views/user/show.rhtml | 2 | ||||
-rw-r--r-- | config/routes.rb | 4 |
6 files changed, 22 insertions, 10 deletions
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 65ab168e9..a935983ac 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_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: request_controller.rb,v 1.8 2007-10-30 14:13:46 francis Exp $ +# $Id: request_controller.rb,v 1.9 2007-10-30 17:31:31 francis Exp $ class RequestController < ApplicationController @@ -46,7 +46,7 @@ class RequestController < ApplicationController @info_request.save @outgoing_message.send_message flash[:notice] = "Your Freedom of Information request has been created and sent on its way." - redirect_to request_url(:id => @info_request) + redirect_to show_request_url(:id => @info_request) end # Save both models diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 3daab0670..a0ac68443 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -4,11 +4,12 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: user_controller.rb,v 1.4 2007-10-30 14:49:08 francis Exp $ +# $Id: user_controller.rb,v 1.5 2007-10-30 17:31:31 francis Exp $ class UserController < ApplicationController + # XXX See helpers/application_helper.rb simplify_url_part fo reverse of expression in SQL below def show - @display_users = User.find(:all, :conditions => [ "name = ?", params[:name] ], :order => "created_at desc") + @display_users = User.find(:all, :conditions => [ "regexp_replace(replace(lower(name), ' ', '-'), '[^a-z0-9_-]', '', 'g') = ?", params[:simple_name] ], :order => "created_at desc") end private diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 9c4c085dd..495c61b61 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.9 2007-10-30 15:03:03 francis Exp $ +# $Id: application_helper.rb,v 1.10 2007-10-30 17:31:31 francis Exp $ module ApplicationHelper @@ -40,6 +40,13 @@ module ApplicationHelper 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 def request_link(info_request) link_to h(info_request.title), show_request_url(:id => info_request) @@ -53,7 +60,11 @@ module ApplicationHelper end def user_link(user) - link_to h(user.name), show_user_url(:name => user.name) + link_to h(user.name), show_user_url(:simple_name => simplify_url_part(user.name)) + end + + def info_request_link(info_request) + link_to h(info_request.title), show_request_url(:id => info_request) end end diff --git a/app/views/body/show.rhtml b/app/views/body/show.rhtml index 46753dfd7..e8332949b 100644 --- a/app/views/body/show.rhtml +++ b/app/views/body/show.rhtml @@ -5,7 +5,7 @@ <p>Freedom of Information requests made to this body:</p> <ul> <% for info_request in @public_body.info_requests %> -<li><%= link_to h(info_request.title), request_url(:id => info_request) %></li> +<li><%= info_request_link(info_request) %></li> <% end %> </ul> diff --git a/app/views/user/show.rhtml b/app/views/user/show.rhtml index 3e2668d01..16cf528c2 100644 --- a/app/views/user/show.rhtml +++ b/app/views/user/show.rhtml @@ -12,7 +12,7 @@ <ul> <% for info_request in display_user.info_requests %> <li> - <%= link_to h(info_request.title), request_url(:id => info_request) %> + <%= info_request_link(info_request) %> on <%= simple_date(info_request.created_at) %> </li> <% end %> diff --git a/config/routes.rb b/config/routes.rb index d4625d897..2ee97376c 100644 --- a/config/routes.rb +++ b/config/routes.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: routes.rb,v 1.17 2007-10-30 15:03:04 francis Exp $ +# $Id: routes.rb,v 1.18 2007-10-30 17:31:32 francis Exp $ ActionController::Routing::Routes.draw do |map| # The priority is based upon order of creation: first created -> highest priority. @@ -25,7 +25,7 @@ ActionController::Routing::Routes.draw do |map| user.signin '/signin', :action => 'signin' user.signup '/signup', :action => 'signup' user.signout '/signout', :action => 'signout' - user.show_user "/user/:name", :action => 'show' + user.show_user "/user/:simple_name", :action => 'show' end map.show_public_body "/body/:short_name", :controller => 'body', :action => 'show' |