Show validation errors in UI, otherwise fail loudly

This commit is contained in:
Artur Beljajev 2019-12-09 22:23:12 +02:00
parent 01c877fe70
commit e5eaac291e

View file

@ -14,11 +14,11 @@ module Admin
def create def create
@api_user = registrar.api_users.build(api_user_params) @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') flash[:notice] = I18n.t('record_created')
redirect_to admin_registrar_api_user_path(@api_user.registrar, @api_user) redirect_to admin_registrar_api_user_path(@api_user.registrar, @api_user)
else else
flash.now[:alert] = I18n.t('failed_to_create_record')
render 'new' render 'new'
end end
end end
@ -34,11 +34,13 @@ module Admin
params[:api_user].delete(:plain_text_password) params[:api_user].delete(:plain_text_password)
end 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') flash[:notice] = I18n.t('record_updated')
redirect_to admin_registrar_api_user_path(@api_user.registrar, @api_user) redirect_to admin_registrar_api_user_path(@api_user.registrar, @api_user)
else else
flash.now[:alert] = I18n.t('failed_to_update_record')
render 'edit' render 'edit'
end end
end end