diff --git a/app/models/site/forms.rb b/app/models/site/forms.rb index 29e54aa..8f6983b 100644 --- a/app/models/site/forms.rb +++ b/app/models/site/forms.rb @@ -11,8 +11,6 @@ class Site # @return Array def params map do |field, definition| - next if EXCLUDED_FIELDS.include? definition['type'] - if ARRAY_FIELDS.include? definition['type'] { field.to_sym => [] } else @@ -21,6 +19,9 @@ class Site end.compact end + # Obtiene la traducción del campo + # + # @return String def t(field) dig(field.to_s, 'label', I18n.locale.to_s) end @@ -46,12 +47,17 @@ class Site forms.include? name.to_s end - # Obtiene un formulario + # Obtiene un formulario con los campos definitivos # # @return Site::Forms::Form def form(name) @cached_forms ||= {} - @cached_forms[name] ||= Form[data.dig('forms', name)] + @cached_forms[name] ||= Form[data.dig('forms', name).reject { |k,_| excluded? k }] + end + + # Detecta si el campo está excluido del formulario final + def excluded?(field) + EXCLUDED_FIELDS.include? field.to_s end end end diff --git a/app/views/contact_mailer/notify_usuaries.html.haml b/app/views/contact_mailer/notify_usuaries.html.haml index bc3d5ef..792660b 100644 --- a/app/views/contact_mailer/notify_usuaries.html.haml +++ b/app/views/contact_mailer/notify_usuaries.html.haml @@ -1,4 +1,4 @@ - @params[:form].each do |field, value| %p - %strong= @params[:form_definition].t(field) || field + ':' + %strong= @params[:form_definition].t(field) + ':' = value diff --git a/app/views/contact_mailer/notify_usuaries.text.haml b/app/views/contact_mailer/notify_usuaries.text.haml index 434a8d7..3e6e488 100644 --- a/app/views/contact_mailer/notify_usuaries.text.haml +++ b/app/views/contact_mailer/notify_usuaries.text.haml @@ -1,3 +1,3 @@ - @params[:form].each do |field, value| - "#{@params[:form_definition].t(field) || field}: #{value}" + "#{@params[:form_definition].t(field)}: #{value}" \