FIX: handle error for duplicate email_in address

This commit is contained in:
Arpit Jalan
2015-04-16 16:09:48 +05:30
parent 3d30bd115d
commit 866d1cd8e3
3 changed files with 12 additions and 0 deletions

View File

@ -87,6 +87,9 @@ class CategoriesController < ApplicationController
if category_params.key? :email_in and category_params[:email_in].length == 0
# properly null the value so the database constrain doesn't catch us
category_params[:email_in] = nil
elsif category_params.key? :email_in and existing_category = Category.find_by(email_in: category_params[:email_in]) and existing_category.id != @category.id
# check if email_in address is already in use for other category
return render_json_error I18n.t('category.errors.email_in_already_exist', {email_in: category_params[:email_in], category_name: existing_category.name})
end
category_params.delete(:position)