Module: CheckoutFormsHelper

Defined in:
app/helpers/checkout_forms_helper.rb

Overview

View helper: checkout forms.

Instance Method Summary collapse

Instance Method Details

#checkout_form_attribute_hidden_fields(checkout_form) ⇒ String

Renders hidden input fields preserving every attribute of a checkout form,
so multi-step checkout flows can carry previously submitted values forward.

Array-valued attributes emit one hidden field per element using the
checkout_form[attr][] naming convention; scalar values emit a single
hidden field. Blank values are skipped.

Parameters:

  • checkout_form (Object)

    the checkout form object whose attributes are re-rendered

Returns:

  • (String)

    HTML-safe hidden input tags for all present attributes



14
15
16
17
18
19
20
21
22
23
24
# File 'app/helpers/checkout_forms_helper.rb', line 14

def checkout_form_attribute_hidden_fields(checkout_form)
  checkout_form.attributes.map do |attr_key, value|
    if value.present?
      if value.is_a? Array
        value.map { |v| hidden_field_tag("checkout_form[#{attr_key}][]", v) }
      else
        hidden_field_tag("checkout_form[#{attr_key}]", value)
      end
    end
  end.flatten.compact.join.html_safe
end