diff --git a/app/views/sites/_form.haml b/app/views/sites/_form.haml index fc88993..14a8eca 100644 --- a/app/views/sites/_form.haml +++ b/app/views/sites/_form.haml @@ -4,8 +4,9 @@ %p.lead= t('.errors.help') %ul - site.errors.messages.each_pair do |attr, error| + - attr = attr.to_s - error.each do |e| - %li= link_to e, '#' + attr.to_s + %li= link_to t('activerecord.attributes.site.' + attr) + ' ' + e, '#' + attr = form_for site, html: { class: form_class(site) } do |f| - unless site.persisted? diff --git a/config/initializers/bootstrap_field_with_errors.rb b/config/initializers/bootstrap_field_with_errors.rb index 56b0a25..71b8e59 100644 --- a/config/initializers/bootstrap_field_with_errors.rb +++ b/config/initializers/bootstrap_field_with_errors.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Adaptar la renderización de campos con error de Rails para que sea # compatible con Bootstrap4. La forma actual rompe los inputs # personalizados. @@ -5,7 +7,7 @@ ActionView::Base.field_error_proc = proc do |html_tag, _| return unless html_tag html = Nokogiri::HTML::DocumentFragment.parse html_tag - html.children.first.attributes['class'].value += ' is-invalid' + html&.children&.first&.attributes&.dig('class')&.value += ' is-invalid' - html.to_s.html_safe + html&.to_s&.html_safe || html_tag end