5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-23 04:46:21 +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 # Helpers
module ApplicationHelper module ApplicationHelper
BRACKETS = /[\[\]]/
# Devuelve el atributo name de un campo anidado en el formato que # Devuelve el atributo name de un campo anidado en el formato que
# esperan los helpers *_field # esperan los helpers *_field
# #
@ -19,6 +21,14 @@ module ApplicationHelper
[root, name] [root, name]
end 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) def plain_field_name_for(*names)
root, name = 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 Genera un listado de checkboxes entre los que se puede elegir para guardar
:ruby :ruby
id = "#{base.gsub(/[\[\]]/, '_')}_#{attribute}".squeeze('_') id = id_for(base, attribute)
name = "#{base}[#{attribute}][]" name = "#{base}[#{attribute}][]"
form_id = "form-#{Nanoid.generate}" form_id = "form-#{Nanoid.generate}"

View file

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

View file

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