5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-22 15:46:21 +00:00

refactor: convertir lista de errores en un componente

This commit is contained in:
f 2024-07-10 17:08:47 -03:00
parent 255ea763b4
commit 5b9cd27a79
No known key found for this signature in database
3 changed files with 29 additions and 38 deletions

View file

@ -0,0 +1,19 @@
- unless post.errors.empty?
- title = t('.errors.title')
- help = t('.errors.help')
= render 'bootstrap/alert' do
%h4= title
%p= help
%ul
- post.errors.each do |attribute, errors|
- if errors.size > 1
%li
%strong= post_label_t attribute, post: post
%ul
- errors.each do |error|
%li= error
- else
%li
%strong= post_label_t attribute, post: post
= errors.first

View file

@ -1,22 +1,4 @@
- unless post.errors.empty?
- title = t('.errors.title')
- help = t('.errors.help')
= render 'bootstrap/alert' do
%h4= title
%p= help
%ul
- post.errors.each do |attribute, errors|
- if errors.size > 1
%li
%strong= post_label_t attribute, post: post
%ul
- errors.each do |error|
%li= error
- else
%li
%strong= post_label_t attribute, post: post
= errors.first
= render 'errors', post: post
-# TODO: habilitar form_for
:ruby
@ -55,3 +37,11 @@
-# Formularios usados por los modales
= yield(:post_form)
-#
Acumulador de formularios dinámicos, se van cargando a medida que se
necesitan en lugar de recursivamente.
Nunca se eliminan los modales una vez que se cargan para poder tener
historial de cambios.
%div{ data: { controller: 'htmx', action: 'htmx:getUrl@window->htmx#beforeend' } }

View file

@ -47,25 +47,7 @@
end
= form_tag url, **options do
- unless post.errors.empty?
- title = t('.errors.title')
- help = t('.errors.help')
= render 'bootstrap/alert' do
%h4= title
%p= help
%ul
- post.errors.each do |attribute, errors|
- if errors.size > 1
%li
%strong= post_label_t attribute, post: post
%ul
- errors.each do |error|
%li= error
- else
%li
%strong= post_label_t attribute, post: post
= errors.first
= render 'errors', post: post
-# Parámetros para HTMX
%input{ type: 'hidden', name: 'hide', value: pluck_param((post.errors.empty? ? :show : :hide), optional: true) }