fix devise error display
This commit is contained in:
parent
0ccfab790b
commit
6a2378b8d7
@ -1,55 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
||||
# devise helper
|
||||
module DeviseHelper
|
||||
def devise_error_messages!
|
||||
return if resource.errors.empty?
|
||||
|
||||
messages = resource.errors.full_messages.map { |msg| content_tag(:p, "- #{msg}.") }
|
||||
.join
|
||||
sentence = I18n.t(
|
||||
"errors.messages.not_saved",
|
||||
count: resource.errors.count,
|
||||
resource: resource.class.model_name.human.downcase
|
||||
)
|
||||
|
||||
html = <<-HTML
|
||||
<div class="bg-red-100 border-l-4 border-red-500 mb-4 p-4 text-red-700" role="alert">
|
||||
<p class="font-bold">Oops!</p>
|
||||
<p>#{sentence}</p>#{messages}
|
||||
</div>
|
||||
HTML
|
||||
|
||||
html.html_safe
|
||||
end
|
||||
|
||||
def devise_simple_error_messages!
|
||||
return if resource.errors.empty?
|
||||
|
||||
sentence = "Ooops!"
|
||||
if resource.errors.count == 1
|
||||
message = resource.errors.full_messages[0]
|
||||
html = <<-HTML
|
||||
<div class="bg-red-lightest border-l-4 border-red text-orange-dark p-4" role="alert">
|
||||
<p class="font-bold">#{sentence}</p>
|
||||
<p> #{message}.</p>
|
||||
</div>
|
||||
HTML
|
||||
else
|
||||
messages = resource.errors.full_messages.map { |msg| content_tag(:li, "#{msg}.") }
|
||||
.join
|
||||
html = <<-HTML
|
||||
<div class="bg-red-100 border-l-4 border-red-500 mb-4 p-4 text-red-700" role="alert">
|
||||
<p class="font-bold">#{sentence}</p>
|
||||
<ul class="list-disc">
|
||||
#{messages}
|
||||
</ul>
|
||||
</div>
|
||||
HTML
|
||||
end
|
||||
|
||||
html.html_safe
|
||||
end
|
||||
end
|
||||
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
@ -8,7 +8,7 @@
|
||||
method: :post, |
|
||||
class: "bg-white mb-4 px-8 pt-6 pb-8 rounded shadow-md" |
|
||||
}) do |f| |
|
||||
= devise_error_messages!
|
||||
= render "devise/shared/error_messages", resource: resource
|
||||
.mb-4
|
||||
= f.label :email, class: "block font-bold mb-2 text-gray-700 text-sm"
|
||||
= f.email_field :email, |
|
||||
|
@ -9,7 +9,7 @@
|
||||
class: "bg-white mb-4 px-8 pt-6 pb-8 rounded shadow-md" |
|
||||
} |
|
||||
) do |f| |
|
||||
= devise_error_messages!
|
||||
= render "devise/shared/error_messages", resource: resource
|
||||
= f.hidden_field :reset_password_token
|
||||
.mb-4
|
||||
= f.label :password, "New Password", |
|
||||
|
@ -8,7 +8,7 @@
|
||||
method: :post, |
|
||||
class: "bg-white mb-4 px-8 pt-6 pb-8 rounded shadow-md" |
|
||||
}) do |f| |
|
||||
= devise_error_messages!
|
||||
= render "devise/shared/error_messages", resource: resource
|
||||
.mb-4
|
||||
= f.label :email, class: "block font-bold mb-2 text-gray-700 text-sm"
|
||||
= f.email_field :email, autofocus: true, autocomplete: "email", |
|
||||
|
@ -10,7 +10,7 @@
|
||||
class: "bg-white mb-4 px-8 pt-6 pb-8 rounded shadow-md" |
|
||||
} |
|
||||
) do |f| |
|
||||
= devise_error_messages!
|
||||
= render "devise/shared/error_messages", resource: resource
|
||||
.mb-4
|
||||
= f.label :email, class: "block font-bold mb-2 text-gray-700 text-sm"
|
||||
%br/
|
||||
|
@ -8,7 +8,7 @@
|
||||
class: "bg-white mb-4 px-8 pt-6 pb-8 rounded shadow-md" |
|
||||
} |
|
||||
) do |f| |
|
||||
= devise_error_messages!
|
||||
= render "devise/shared/error_messages", resource: resource
|
||||
.mb-4
|
||||
= f.label :email, class: "block font-bold mb-2 text-gray-700 text-sm"
|
||||
= f.email_field :email, |
|
||||
|
@ -8,14 +8,7 @@
|
||||
class: "bg-white mb-4 px-8 pt-6 pb-8 rounded shadow-md" |
|
||||
} |
|
||||
) do |f| |
|
||||
= devise_simple_error_messages!
|
||||
- if flash.present?
|
||||
.bg-red-100.border-l-4.border-red-500.text-red-700.p-4.mb-4{:role => "alert"}
|
||||
%p.font-bold Oops!
|
||||
- flash.each do |name, msg|
|
||||
= content_tag :p, |
|
||||
msg.humanize, |
|
||||
id: "flash_#{name}" if msg.is_a?(String) |
|
||||
= render "devise/shared/error_messages", resource: resource
|
||||
.mb-4
|
||||
= f.label :email, class: "block text-gray-700 text-sm font-bold mb-2"
|
||||
= f.email_field :email, autofocus: true, autocomplete: "email", |
|
||||
|
@ -1,6 +1,6 @@
|
||||
- if resource.errors.any?
|
||||
#error_explanation
|
||||
%h2
|
||||
%h2.bg-red-100.border-l-4.border-red-500.mb-4.p-4.text-red-700.font-bold
|
||||
= I18n.t("errors.messages.not_saved", |
|
||||
count: resource.errors.count, |
|
||||
resource: resource.class.model_name.human.downcase) |
|
||||
|
@ -9,7 +9,7 @@
|
||||
class: "bg-white mb-4 px-8 pt-6 pb-8 rounded shadow-md" |
|
||||
} |
|
||||
) do |f| |
|
||||
= devise_error_messages!
|
||||
= render "devise/shared/error_messages", resource: resource
|
||||
.mb-4
|
||||
= f.label :email, class: "block font-bold mb-2 text-gray-700 text-sm"
|
||||
= f.email_field :email, |
|
||||
|
@ -16,7 +16,6 @@
|
||||
%strong.block.font-medium.text-gray-900 Ok
|
||||
%p.mt-1.text-sm.text-gray-700
|
||||
= flash.notice
|
||||
|
||||
:javascript
|
||||
function hideNotice() {
|
||||
const notification = document.querySelector('#flash')
|
||||
|
@ -12,6 +12,6 @@
|
||||
= javascript_importmap_tags
|
||||
%body
|
||||
= render "layouts/header"
|
||||
= render "layouts/merged_messages"
|
||||
= render "layouts/messages"
|
||||
= yield
|
||||
= render "layouts/footer"
|
||||
|
Loading…
Reference in New Issue
Block a user