From febac442d928b2dac7d28b4b972a7254a48ca2d8 Mon Sep 17 00:00:00 2001 From: Viktor Palmkvist Date: Fri, 9 Aug 2013 22:09:54 +0200 Subject: [PATCH] Added backwards compatibility for topic creation --- lib/topic_creator.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/topic_creator.rb b/lib/topic_creator.rb index 2b932cd9552..42d0e91275f 100644 --- a/lib/topic_creator.rb +++ b/lib/topic_creator.rb @@ -39,7 +39,14 @@ class TopicCreator topic_params[:archetype] = @opts[:archetype] if @opts[:archetype].present? topic_params[:subtype] = @opts[:subtype] if @opts[:subtype].present? - category = Category.where(id: @opts[:category]).first + # Temporary fix to allow older clients to create topics. + # When all clients are updated the category variable should + # be set directly to the contents of the if statement. + category = if @opts[:category].is_a? Integer || @opts[:category] =~ /^\d+$/ + Category.where(id: @opts[:category]).first + else + Category.where(name: @opts[:category]).first + end @guardian.ensure_can_create!(Topic,category) topic_params[:category_id] = category.id if category.present?