From 183430adb6feff6167a39eb3751bba14f8c7a099 Mon Sep 17 00:00:00 2001 From: Matchu Date: Fri, 20 May 2011 19:50:06 -0400 Subject: [PATCH] remove non-alphanumeric chars from item pretty urls mainly because they were causing the router to freak out when they contained periods, because that looks like a format, e.g. show.html --- app/models/item.rb | 3 ++- public/javascripts/wardrobe.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/item.rb b/app/models/item.rb index cf85ac9e..3b17d414 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -156,8 +156,9 @@ class Item < ActiveRecord::Base } end + URL_CHAR_BLACKLIST = /[^a-z0-9\-]/i def name_for_url - name.downcase.gsub(' ', '-') + name.downcase.gsub(' ', '-').gsub(URL_CHAR_BLACKLIST, '') end def to_param diff --git a/public/javascripts/wardrobe.js b/public/javascripts/wardrobe.js index 8b163917..84198af5 100644 --- a/public/javascripts/wardrobe.js +++ b/public/javascripts/wardrobe.js @@ -126,7 +126,7 @@ function Wardrobe() { } function getNameForSlug() { - return item.name.toLowerCase().replace(/ /g, '-'); + return item.name.toLowerCase().replace(/ /g, '-').replace(/[^a-z0-9\-]/i, ''); } function getSlug() {