Module: ApplicationHelper

Defined in:
app/helpers/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#gds_error_messages(model:, method:) ⇒ Object

Renders error messages for an attribute from a model or form object based on active model, but renders them GDS style (span with a class of 'error-message')

Parameters:

  • model (ActiveModel::Model)

    The model or form object to get the errors from

  • method (Symbol)

    The attribute that you want the error messages for


22
23
24
25
26
27
28
# File 'app/helpers/application_helper.rb', line 22

def gds_error_messages(model:, method:)
  errors = model.errors
  return '' unless errors.include?(method)
  errors.full_messages_for(method).each do |error|
    concat ('span', error, class: 'error-message')
  end
end

#gds_multiple_choices_with_guidance(form:, method:, choices:) ⇒ String

Renders a group of checkboxes following GDS guidelines with guidance text

Parameters:

  • form (ActionView::Helpers::FormBuilder)
  • method (Symbol)

    The active model attribute to generate the multiple choices for

  • choices (Array<Array>)

    An array of arrays where the inner array contains the 'key', the 'display text' and 'guidance id' (nil for none) guidance id will mean more to you if you are familiar with GDS multiple choices with guidance

Returns:

  • (String)

    The HTML to render


11
12
13
14
15
# File 'app/helpers/application_helper.rb', line 11

def gds_multiple_choices_with_guidance(form:, method:, choices:)
  form.collection_check_boxes method, choices, :first, :second do |b|
    gds_checkbox_with_guidance(b)
  end
end