From e5eaac291ee7d9a713baaec182028214600056f0 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 9 Dec 2019 22:23:12 +0200 Subject: [PATCH] Show validation errors in UI, otherwise fail loudly --- app/controllers/admin/api_users_controller.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/api_users_controller.rb b/app/controllers/admin/api_users_controller.rb index 1343e2f91..4b79ffdaa 100644 --- a/app/controllers/admin/api_users_controller.rb +++ b/app/controllers/admin/api_users_controller.rb @@ -14,11 +14,11 @@ module Admin def create @api_user = registrar.api_users.build(api_user_params) - if @api_user.save + if @api_user.valid? + @api_user.save! flash[:notice] = I18n.t('record_created') redirect_to admin_registrar_api_user_path(@api_user.registrar, @api_user) else - flash.now[:alert] = I18n.t('failed_to_create_record') render 'new' end end @@ -34,11 +34,13 @@ module Admin params[:api_user].delete(:plain_text_password) end - if @api_user.update(api_user_params) + @api_user.attributes = api_user_params + + if @api_user.valid? + @api_user.save! flash[:notice] = I18n.t('record_updated') redirect_to admin_registrar_api_user_path(@api_user.registrar, @api_user) else - flash.now[:alert] = I18n.t('failed_to_update_record') render 'edit' end end