diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index 3bef1bd62c7..e3db162fbad 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -118,10 +118,14 @@ class CategoriesController < ApplicationController def create guardian.ensure_can_create!(Category) - position = category_params.delete(:position) - @category = Category.create(category_params.merge(user: current_user)) + @category = + begin + Category.new(category_params.merge(user: current_user)) + rescue ArgumentError => e + return render json: { errors: [e.message] }, status: 422 + end if @category.save @category.move_to(position.to_i) if position @@ -134,8 +138,6 @@ class CategoriesController < ApplicationController else return render_json_error(@category) unless @category.save end - rescue ArgumentError => e - render json: { errors: [e.message] }, status: 422 end def update