From 69c7b5aeedfdfa49136a12cedf4b588e137839cd Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 12 Feb 2013 17:39:31 -0500 Subject: [PATCH] Support category names with spaces --- .../discourse/routes/list_category_route.js.coffee | 13 ++++++++----- app/controllers/list_controller.rb | 2 +- app/models/category_list.rb | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/discourse/routes/list_category_route.js.coffee b/app/assets/javascripts/discourse/routes/list_category_route.js.coffee index dfd1519ec5b..5e38ad1acd2 100644 --- a/app/assets/javascripts/discourse/routes/list_category_route.js.coffee +++ b/app/assets/javascripts/discourse/routes/list_category_route.js.coffee @@ -1,10 +1,13 @@ window.Discourse.ListCategoryRoute = Discourse.FilteredListRoute.extend - serialize: (params) -> slug: params.get('slug') - setupController: (controller, model) -> + + slug = Em.get(model, 'slug') + category = Discourse.get('site.categories').findProperty('slug', slug) + category ||= Discourse.Category.create(name: slug, slug: slug) + listController = @controllerFor('list') - listController.set('filterMode', "category/#{model.slug}") - listController.load("category/#{model.slug}").then (topicList) => + listController.set('filterMode', "category/#{category.get('slug')}") + listController.load("category/#{category.get('slug')}").then (topicList) => listController.set('canCreateTopic', topicList.get('can_create_topic')) - listController.set('category', Discourse.Category.create(name: model.slug)) + listController.set('category',category) @controllerFor('listTopics').set('content', topicList) diff --git a/app/controllers/list_controller.rb b/app/controllers/list_controller.rb index 62757c7b9db..ef2092d7f62 100644 --- a/app/controllers/list_controller.rb +++ b/app/controllers/list_controller.rb @@ -35,7 +35,7 @@ class ListController < ApplicationController list = nil # If they choose uncategorized, return topics NOT in a category - if params[:category] == SiteSetting.uncategorized_name + if params[:category] == Slug.for(SiteSetting.uncategorized_name) or params[:category] == SiteSetting.uncategorized_name list = query.list_uncategorized else category = Category.where(slug: params[:category]).includes(:featured_users).first diff --git a/app/models/category_list.rb b/app/models/category_list.rb index 8a0cec9ff83..09d5556363c 100644 --- a/app/models/category_list.rb +++ b/app/models/category_list.rb @@ -30,7 +30,7 @@ class CategoryList uncategorized = Category.new({name: SiteSetting.uncategorized_name, - slug: SiteSetting.uncategorized_name, + slug: Slug.for(SiteSetting.uncategorized_name), featured_topics: uncategorized_topics}.merge(totals)) # Find the appropriate place to insert it: