The problem was that project (and context) names were made into URLs via the 'urlize' method which substituted spaces for underscores and downcased the string. This was then converted back to the real project name by the Rails method 'humanize', which substituted spaces for underscores and Capitalized the string (i.e. only the first word was given an initial capital). This meant that visiting /project/show/project_name would fail if the real project name was either 'Project Name' or 'project name'.

I altered 'urlize' to maintain the capitalization that was entered, and created a new method 'deurlize' that just reversed this change (i.e. swapped underscores for spaces, but left capitalization as is).


git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@101 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
bsag 2005-06-07 18:39:51 +00:00
parent 9587984ecb
commit 977ca82306
5 changed files with 8 additions and 4 deletions

View file

@ -30,4 +30,8 @@ class ApplicationController < ActionController::Base
error_messages_for( obj ) unless instance_eval("@#{obj}").nil?
end
def deurlize(name)
name.to_s.gsub(/_/, " ")
end
end

View file

@ -24,7 +24,7 @@ class ContextController < ApplicationController
# e.g. <home>/project/show/<project_name> shows just <project_name>.
#
def show
@context = Context.find_by_name(@params["name"].humanize)
@context = Context.find_by_name(deurlize(@params["name"]))
@places = Context.find(:all, :order => "position ASC")
@projects = Project.find(:all, :order => "position ASC")
@page_title = "TRACKS::Context: #{@context.name}"

View file

@ -24,7 +24,7 @@ class ProjectController < ApplicationController
# e.g. <home>/project/show/<project_name> shows just <project_name>.
#
def show
@project = Project.find_by_name(@params["name"].humanize)
@project = Project.find_by_name(deurlize(@params["name"]))
@places = Context.find(:all, :order => "position ASC")
@projects = Project.find(:all, :order => "position ASC")
@page_title = "TRACKS::Project: #{@project.name}"

View file

@ -28,7 +28,7 @@ module ApplicationHelper
end
def urlize(name)
name.to_s.gsub(/ /, "_").downcase
name.to_s.gsub(/ /, "_")
end

View file

@ -11,7 +11,7 @@
-- ------------------------------------------------------------
INSERT INTO contexts (id,name,hide, position) VALUES (1,'agenda',0, 1);
INSERT INTo contexts (id,name,hide, position) VALUES (2,'call',0, 2);
INSERT INTO contexts (id,name,hide, position) VALUES (2,'call',0, 2);
INSERT INTO contexts (id,name,hide, position) VALUES (3,'email',0, 3);
INSERT INTO contexts (id,name,hide, position) VALUES (4,'errand',0, 4);
INSERT INTO contexts (id,name,hide, position) VALUES (5,'lab',0, 5);