Class: Pulse::Forms::ErrorExplanation
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Pulse::Forms::ErrorExplanation
- Defined in:
- app/components/pulse/forms/error_explanation.rb
Overview
Render error message box for an ActiveModel resource
Instance Method Summary collapse
- #errors ⇒ Object
-
#initialize(resource:, **options) ⇒ ErrorExplanation
constructor
A new instance of ErrorExplanation.
- #render? ⇒ Boolean
Constructor Details
#initialize(resource:, **options) ⇒ ErrorExplanation
Returns a new instance of ErrorExplanation.
7 8 9 10 11 12 13 14 15 |
# File 'app/components/pulse/forms/error_explanation.rb', line 7 def initialize(resource:, **) @resource = resource @options = @options[:classes] = class_names( 'pulse-bg-error-50 pulse-text-error pulse-px-3 pulse-py-2', 'pulse-font-medium pulse-rounded-lg pulse-my-3', [:classes] ) end |
Instance Method Details
#errors ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'app/components/pulse/forms/error_explanation.rb', line 17 def errors @errors = ActiveModel::Errors.new(resource) # Only display the last of each attribute error, to avoid needless # duplication. resource.errors.group_by(&:attribute).values.map(&:last).each do |error| @errors.add(error.attribute, error.) end @errors end |
#render? ⇒ Boolean
27 28 29 |
# File 'app/components/pulse/forms/error_explanation.rb', line 27 def render? resource.errors.any? end |