Class: Railsboot::ErrorsComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/railsboot/errors_component.rb

Overview

ViewComponent: renders the errors block.

Instance Method Summary collapse

Constructor Details

#initialize(*objects, **html_attributes) ⇒ ErrorsComponent

Returns a new instance of ErrorsComponent.

Parameters:

  • objects (Array<Object>)

    records whose errors are rendered

  • html_attributes (Hash)

    additional HTML attributes forwarded to Railsboot::AlertComponent

Options Hash (**html_attributes):

  • :class (String)

    additional CSS classes, merged with the alert's own classes



7
8
9
10
# File 'app/components/railsboot/errors_component.rb', line 7

def initialize(*objects, **html_attributes)
  @objects = Array(objects)
  @html_attributes = html_attributes
end

Instance Method Details

#error_messagesArray<String>

Flattened full error messages across all passed objects

Returns:

  • (Array<String>)


20
21
22
# File 'app/components/railsboot/errors_component.rb', line 20

def error_messages
  errors.map(&:full_messages).flatten
end

#errorsArray<ActiveModel::Errors>

Flattened errors across all passed objects

Returns:

  • (Array<ActiveModel::Errors>)


14
15
16
# File 'app/components/railsboot/errors_component.rb', line 14

def errors
  @objects.map(&:errors).flatten
end

#render?Boolean

Whether the component renders (only when error messages are present)

Returns:

  • (Boolean)


26
27
28
# File 'app/components/railsboot/errors_component.rb', line 26

def render?
  error_messages.any?
end