Method: CCS::FrontendHelpers::GovUKFrontend::ErrorMessage#govuk_error_message_with_model

Defined in:
lib/ccs/frontend_helpers/govuk_frontend/error_message.rb

#govuk_error_message_with_model(model, attribute) ⇒ NilClass, ActiveSupport::SafeBuffer

Generates the HTML for the GOV.UK Error message component using the error messages in an ActiveModel

Parameters:

  • model (ActiveModel)

    model that will be used to find the error message

  • attribute (String, Symbol)

    the attribute that has an error

  • options (Hash)

    options that will be used in customising the HTML

Returns:

  • (NilClass, ActiveSupport::SafeBuffer)

    if the error message is not on the model it will return nil, otherwise it returns the error message HTML



37
38
39
40
41
42
# File 'lib/ccs/frontend_helpers/govuk_frontend/error_message.rb', line 37

def govuk_error_message_with_model(model, attribute, **)
  error_message = model.errors[attribute].first
  return unless error_message

  Components::GovUK::ErrorMessage.new(context: self, message: error_message, attribute: attribute, **).render
end