Module: LightningUiKit::Errors
- Included in:
- DropzoneComponent, FileInputComponent, InputComponent, SelectComponent, SwitchComponent, TextareaComponent
- Defined in:
- app/components/lightning_ui_kit/errors.rb
Instance Method Summary collapse
-
#error_messages ⇒ Object
TODO: simplify this code.
- #has_errors? ⇒ Boolean
- #infer_errors_from_association ⇒ Object
Instance Method Details
#error_messages ⇒ Object
TODO: simplify this code
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/components/lightning_ui_kit/errors.rb', line 8 def return @error if @error.present? return @error_messages if @error_messages.present? if @form.present? @error_messages = @form.object.errors.(@name.to_sym) if @error_messages.blank? @error_messages = infer_errors_from_association end end @error_messages = @error_messages&.to_a&.join(". ") end |
#has_errors? ⇒ Boolean
3 4 5 |
# File 'app/components/lightning_ui_kit/errors.rb', line 3 def has_errors? .present? end |
#infer_errors_from_association ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/components/lightning_ui_kit/errors.rb', line 21 def infer_errors_from_association association = if @name.to_s.end_with?("_ids") return unless @form.object.respond_to?(:reflect_on_association) @form.object.class.reflect_on_association(@name.to_s.chomp("_ids").pluralize.to_sym) else return unless @form.object.respond_to?(:reflect_on_all_associations) @form.object.class.reflect_on_all_associations.find do |a| a.macro == :belongs_to && a.foreign_key.to_s == @name.to_s end end @form.object.errors.(association&.name&.to_sym) if association end |