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

refactor: no repetir código

This commit is contained in:
f 2024-05-23 17:47:02 -03:00
parent 6673660fb6
commit 1e13fc4621
No known key found for this signature in database
4 changed files with 13 additions and 4 deletions

View file

@ -2,6 +2,8 @@
# Helpers
module ApplicationHelper
BRACKETS = /[\[\]]/
# Devuelve el atributo name de un campo anidado en el formato que
# esperan los helpers *_field
#
@ -19,6 +21,14 @@ module ApplicationHelper
[root, name]
end
# Obtiene un ID
#
# @param base [String]
# @param attribute [String, Symbol]
def id_for(base, attribute)
"#{base.gsub(BRACKETS, '_')}_#{attribute}".squeeze('_')
end
def plain_field_name_for(*names)
root, name = field_name_for(*names)

View file

@ -1,7 +1,7 @@
-#
Genera un listado de checkboxes entre los que se puede elegir para guardar
:ruby
id = "#{base.gsub(/[\[\]]/, '_')}_#{attribute}".squeeze('_')
id = id_for(base, attribute)
name = "#{base}[#{attribute}][]"
form_id = "form-#{Nanoid.generate}"

View file

@ -8,7 +8,7 @@
del formulario principal porque no se pueden anidar.
:ruby
id = "#{base.gsub(/[\[\]]/, '_')}_#{attribute}".squeeze('_')
id = id_for(base, attribute)
name = "#{base}[#{attribute}][]"
form_id = "form-#{Nanoid.generate}"
modal_id = "modal-#{Nanoid.generate}"

View file

@ -3,8 +3,7 @@
guardar, pero no se pueden agregar nuevos.
:ruby
# @todo Convertir en un helper
id = "#{base.gsub(/[\[\]]/, '_')}_#{attribute}".squeeze('_')
id = id_for(base, attribute)
name = "#{base}[#{attribute}][]"
form_id = "form-#{Nanoid.generate}"