From 689521c6ed9f307cd8a412a58955cd4d8985c3ef Mon Sep 17 00:00:00 2001 From: "Dominik M. Kwiatek" Date: Fri, 22 May 2020 22:14:40 +0100 Subject: [PATCH] Replace devise_error_messages! with partial --- app/views/devise/confirmations/new.haml | 2 +- app/views/devise/passwords/edit.haml | 2 +- app/views/devise/passwords/new.haml | 2 +- app/views/devise/registrations/new.haml | 2 +- app/views/devise/shared/_error_messages.haml | 9 +++++++++ app/views/devise/unlocks/new.haml | 2 +- app/views/settings/_account.haml | 2 +- 7 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 app/views/devise/shared/_error_messages.haml diff --git a/app/views/devise/confirmations/new.haml b/app/views/devise/confirmations/new.haml index ba3a40fa..68c415ed 100644 --- a/app/views/devise/confirmations/new.haml +++ b/app/views/devise/confirmations/new.haml @@ -6,7 +6,7 @@ .card-body %h1 Resend confirmation instructions = bootstrap_form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| - = devise_error_messages! + = render "devise/shared/error_messages", resource: resource = f.text_field :screen_name, autofocus: true, label: 'User name' = f.submit 'Resend confirmation instructions', class: 'btn btn-primary mb-3' diff --git a/app/views/devise/passwords/edit.haml b/app/views/devise/passwords/edit.haml index 1ad2365f..44c99fc1 100644 --- a/app/views/devise/passwords/edit.haml +++ b/app/views/devise/passwords/edit.haml @@ -6,7 +6,7 @@ .card-body %h1 Change your password = bootstrap_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| - = devise_error_messages! + = render "devise/shared/error_messages", resource: resource = f.hidden_field :reset_password_token diff --git a/app/views/devise/passwords/new.haml b/app/views/devise/passwords/new.haml index 16d44834..2ddf1b1b 100644 --- a/app/views/devise/passwords/new.haml +++ b/app/views/devise/passwords/new.haml @@ -6,7 +6,7 @@ .card-body %h1 Forgot your password? = bootstrap_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| - = devise_error_messages! + = render "devise/shared/error_messages", resource: resource = f.email_field :email, autofocus: true, label: 'Email address' = f.submit 'Send me password reset instructions', class: 'btn btn-primary mb-3' diff --git a/app/views/devise/registrations/new.haml b/app/views/devise/registrations/new.haml index 35d6c10e..6054ed32 100644 --- a/app/views/devise/registrations/new.haml +++ b/app/views/devise/registrations/new.haml @@ -6,7 +6,7 @@ .card-body %h1= t('views.sessions.new') = bootstrap_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| - = devise_error_messages! + = render "devise/shared/error_messages", resource: resource = f.text_field :screen_name, autofocus: true, label: t('views.settings.account.username') = f.email_field :email, autofocus: false, label: t('views.settings.account.email') diff --git a/app/views/devise/shared/_error_messages.haml b/app/views/devise/shared/_error_messages.haml new file mode 100644 index 00000000..79ff8fcb --- /dev/null +++ b/app/views/devise/shared/_error_messages.haml @@ -0,0 +1,9 @@ +- if resource.errors.any? + #error_explanation + %h2 + = I18n.t("errors.messages.not_saved", + count: resource.errors.count, + resource: resource.class.model_name.human.downcase) + %ul + - resource.errors.full_messages.each do |message| + %li= message diff --git a/app/views/devise/unlocks/new.haml b/app/views/devise/unlocks/new.haml index a099864e..514dec86 100644 --- a/app/views/devise/unlocks/new.haml +++ b/app/views/devise/unlocks/new.haml @@ -4,7 +4,7 @@ = render 'layouts/messages' = bootstrap_form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| - = devise_error_messages! + = render "devise/shared/error_messages", resource: resource = f.email_field :email, autofocus: true, label: 'Email address' diff --git a/app/views/settings/_account.haml b/app/views/settings/_account.haml index e1fea70f..b089c13c 100644 --- a/app/views/settings/_account.haml +++ b/app/views/settings/_account.haml @@ -3,7 +3,7 @@ = bootstrap_form_for(resource, as: resource_name, url: '/settings/account', html: { method: :put }) do |f| = render 'modal/password', f: f - = devise_error_messages! + = render "devise/shared/error_messages", resource: resource = f.text_field :screen_name, autofocus: true, label: t('views.settings.account.username')